请问各位朋友关于变量赋初值的问题?
请问int t=0;跟int t(0);这两种赋值方法有什么不同,第二种来自哪里呢,为什么从来都没有见过?
程序代码:
#include<stdio.h> int main(){ //int a(3003); int a = 3003; printf("%d",a); return 0; }
以上两种方法得到的结果是一样的!
root@localhost:~# cat a.c #include<stdio.h> int main(){ int a(3003); // int a = 3003; printf("%d",a); return 0; } root@localhost:~# gcc a.c a.c: In function 'main': a.c:3:11: error: expected declaration specifiers or '...' before numeric constant int a(3003); ^ a.c:5:17: error: 'a' undeclared (first use in this function) printf("%d",a); ^ a.c:5:17: note: each undeclared identifier is reported only once for each function it appears in root@localhost:~#