int a;是定义还是声明?

_Wayne_ _Wayne_ 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#include <stdio.h>
int a;
int a = 1;

int main(void)
{
printf("a = %d\n",a);
}
在VC中不能成功,在CFree和linux下都能成功。

另外在linux下也做了另一个试验:

root@ubuntu:/home/hello# ls
hello.c hello-test.c hello-test.h
root@ubuntu:/home/hello# cat hello-test.c
#include <stdio.h>
volatile int a=1;

void puta(void)
{
printf("a = %d in hello-test\n",a);
}
root@ubuntu:/home/hello# cat hello-test.h
void puta(void);
root@ubuntu:/home/hello# cat hello.c
#include <stdio.h>
#include "hello-test.h"
int a;

int *p;

int *p2;


int *p3;
int main()
{
a = 2;
printf("a = %d\n*p = %p,*p2 = %p, *p3 = %p\n",a,p,p2,p3);
puta();
return 0;
}
root@ubuntu:/home/hello# gcc hello.c hello-test.c -o hello
root@ubuntu:/home/hello# ./hello
a = 2
*p = (nil),*p2 = (nil), *p3 = (nil)
a = 2 in hello-test
root@ubuntu:/home/hello#


从结果中可以看出,对hello.c中的a 进行修改实际就是对hello-test.c中的a进行修改。
那么请问int a;是声明吗????不分配内存吗????还是有其它原因???
求解ing!!!!!!!!!!!!!!!!!!
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
_Wayne_
C语言 70,040 成员 243,237 内容