这就是我如何看待它,将我在互联网上找到的点点滴滴放在一起。我的观点可能是歪曲的。
一些基本的例子。
int x;
// The type specifer is int
// Declarator x(identifier) defines an object of the type int
// Declares and defines
int x = 9;
// Inatializer = 9 provides the initial value
// Inatializes
C11 标准 6.7 规定标识符的定义是该标识符的声明:
— 对于一个对象,导致为该对象保留存储空间;
— 对于函数,包括函数体;
int main() // Declares. Main does not have a body and no storage is reserved
int main(){ return 0; }
// Declares and defines. Declarator main defines
// an object of the type int only if the body is included.
下面的例子
int test(); Will not compile. undefined reference to main
int main(){} Will compile and output memory address.
// int test();
int main(void)
{
// printf("test %p \n", &test); will not compile
printf("main %p \n",&main);
int (*ptr)() = main;
printf("main %p \n",&main);
return 0;
}
extern int a; // Declares only.
extern int main(); //Declares only.
extern int a = 9; // Declares and defines.
extern int main(){}; //Declares and defines. .