c定义和声明 [英] c definition and declaration

查看:112
本文介绍了c定义和声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我在c ..

是否

int a;

是声明还是定义?

将在写入时分配内存...

解决方案

< blockquote>这是一个暂定的定义;我通常在标题

文件中使用声明''extern int a'并在一个.c文件中使用一个暂定定义:''int a''。


亲切的问候,


Jos


将分配内存。虽然您没有设置号码,但一个号码将存储在一个号码中。如果你


cout<< a<< ENDL;


之后;然后仍会显示一个数字。


没有任何关于它的试探性。内存已分配。这使它成为一个定义。它没有初始化为任何特定值,但这是无关紧要的。


作为定义,它不应该在头文件中。


plz tell me that in c..
whether
int a;
is declaration or definition??
will memory be allocated at the time it is written...

解决方案

It is a tentative definition; I normally use the declaration ''extern int a'' in a header
file and use one tentative definition in exactly one .c file: ''int a''.

kind regards,

Jos


memory will be allocated. Although you have set no number, a number will be stored in a. If you

cout << a << endl;

after int a; then a number is still displayed.


Nothing tentative about it. Memory is allocated. That makes it a definition. It''s not initialized to any particular value but that is irrelevant.

As a definition, it is not supposed to be in a header file.


这篇关于c定义和声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆