int a;是定义还是声明?
#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!!!!!!!!!!!!!!!!!!
...全文
相关推荐
程序设计-函数的声明与函数的原型.pptx
例如,`max`函数的定义如下:```cint max(int a, int b){ return (a > b) ?
C++ 前置声明详解及实例
dValue) { // 函数的实现}```二、自定义类型的前置声明在C++中,我们可以使用前置声明来声明一个自定义类型,并在后续的代码中实现该类型。
函数的定义和申明
例如:```cppextern int a;```这行代码声明了一个名为`a`的外部整型变量,但不会为它分配存储空间。编译器会在链接阶段查找该变量的定义,并将其绑定到正确的存储位置。
在名字空间中声明类和成员函数定义.pdf
通常,我们是在一个专门的头文件中声明一个类,并在不同的源文件中独立地定义其成员函数。那么如何将名字空间成员类分离成多个源文件呢?
extern声明辨析
**答案与分析**:- 如果在函数声明中使用`extern`关键字,如`extern int f();`,它仅表示该函数在其他地方定义。


