开发者

Declare in C == define in C++? [duplicate]

开发者 https://www.devze.com 2022-12-17 06:16 出处:网络
This question already has answers here: Closed 12 years ago. Possible Duplicate: What is the difference between a definition and a declaration?开发者_JS百科
This question already has answers here: Closed 12 years ago.

Possible Duplicate:

What is the difference between a definition and a declaration? 开发者_JS百科

Is it correct that to declare in C is equal to define in C++?

int a;     /* to declare variabel a in C */
int b = 2; /* to declare and initialize in C */


int c;     // to define in C++ 
int d = 4; // to define and initialize in C++ 


No.

For functions, I've seen "declare" being used for just writing the header, whereas "define" was used for writing the body.

However, it's all natural language. "declare" as in you C example seems correct for both C and C++.


In C, declaring means to tell the compiler it exists whereas defining is assigning an actual value to it.

I see no reason why this would be different in C++


yes it should be

0

精彩评论

暂无评论...
验证码 换一张
取 消