请问各位朋友关于变量赋初值的问题?
请问int t=0;跟int t(0);这两种赋值方法有什么不同,第二种来自哪里呢,为什么从来都没有见过?
程序代码:
#include<stdio.h>
int main(){
//int a(3003);
int a = 3003;
printf("%d",a);
return 0;
}以上两种方法得到的结果是一样的!
程序代码:
#include<stdio.h>
int main(){
//int a(3003);
int a = 3003;
printf("%d",a);
return 0;
}
2019-06-17 15:51
2019-06-17 16:01
程序代码: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:~#
2019-06-17 16:18
2019-06-17 16:24