在 C 中声明 == 在 C 中定义++?

发布于 2024-08-19 06:05:23 字数 564 浏览 8 评论 0原文

可能的重复:
定义和声明之间有什么区别?< /a>

在 C 中声明等于在 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++ 

Possible Duplicate:
What is the difference between a definition and a declaration?

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++ 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一杯敬自由 2024-08-26 06:05:23

不。

对于函数,我见过“declare”仅用于编写标题,而“define”用于编写主体。

然而,这都是自然语言。 C 示例中的“声明”对于 C 和 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++.

养猫人 2024-08-26 06:05:23

在 C 中,声明意味着告诉编译器它存在,而定义则是为其分配实际值。

我看不出为什么这在 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++

梦言归人 2024-08-26 06:05:23

是的
应该是

yes
it should be

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文