gpt4 book ai didi

c++ - 功能原型(prototype)制作,程序暂停

转载 作者:搜寻专家 更新时间:2023-10-31 01:37:23 24 4
gpt4 key购买 nike

这是一个带有函数原型(prototype)的程序。

#include <iostream>
using namespace std;

void print(string name);

int main(void)
{
string user;
cout << "Hello, what's your name?";
cout << "Name: ";
print(user);
return(0);
}

void print(string name)
{
cout << "Hello " << name << " my dear friend! :) \n";
}

我知道函数原型(prototype)是一种提醒编译器的方式(在我们的例子中),void print(string name) 位于程序的某处。由于计算机从左到右、从上到下“读取”,当计算机在执行过程中搜索函数时,程序是否可能(或更准确地说,符合逻辑)“暂停”?

最佳答案

Since the computer "reads" left to right, top to bottom, is it possible (or more correctly, logical) that the program "pauses" as the copmuter searches for the function during execution?

main 中对 print 的调用(以及可能调用该函数的任何其他函数)在链接时解析。执行时不需要搜索。

关于c++ - 功能原型(prototype)制作,程序暂停,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34182925/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com