#include <stdio.h>
#include <stdlib.h>
int main (int argc, char **argv)
{
char a[] = {‘a‘,‘b‘,‘c‘,‘d‘,‘e‘};
char b[] = "abcde";
char c[][3] = {{ ‘a‘ , ‘b‘ , ‘c‘ },{ ‘d‘ , ‘e‘ , ‘f‘ },{ ‘g‘ ,‘h‘ , ‘j‘ },{ ‘k‘ , ‘h‘ , ‘l‘ }};
char *p = 0;
char d[][5] = {"abcd","efgh","ijkl","mnol"};
/*
printf("size of a[] is:%d\n",sizeof(a));
printf("size of b[] is:%d\n",sizeof(b)); //这样可以通过。
*/
printf("size of char is:%d\n",sizeof(char));
printf("size of short is:%d\n",sizeof(short));
printf("size of int is:%d\n",sizeof(int));
printf("size of short int is:%d\n",sizeof(short int));
printf("size of lont int is:%d\n",sizeof(long int));
printf("size of float is:%d\n",sizeof(float));
printf("size of double is:%d\n",sizeof(double));
/*编译报错,具体原因不清楚。但变量放在函数前面就没错了。
得自网上:
经过测试发现
在VC中编译c程序,在一个大括号括起的范围内,如果变量声明放在了函数调用的后面,那么编译的时候就会报错:
syntax error : missing ‘;‘ before ‘type‘
然后你可以修改为把变量声明放在函数调用之前。就会顺利通过编译。
这个问题在vc编译c++程序,或者gcc编译c程序的时候都不会出现,仅仅在vc编译c程序的时候才会出现.
D:\winshare\CBasis\practice\practice3.c(29) : error C2143: syntax error : missing ‘;‘ before ‘type‘
D:\winshare\CBasis\practice\practice3.c(30) : error C2143: syntax error : missing ‘;‘ before ‘type‘
D:\winshare\CBasis\practice\practice3.c(31) : error C2143: syntax error : missing ‘;‘ before ‘type‘
D:\winshare\CBasis\practice\practice3.c(33) : error C2065: ‘c‘ : undeclared identifier
D:\winshare\CBasis\practice\practice3.c(34) : error C2109: subscript requires array or pointer type
D:\winshare\CBasis\practice\practice3.c(35) : error C2109: subscript requires array or pointer type
D:\winshare\CBasis\practice\practice3.c(35) : error C2109: subscript requires array or pointer type
D:\winshare\CBasis\practice\practice3.c(37) : error C2065: ‘p‘ : undeclared identifier
D:\winshare\CBasis\practice\practice3.c(39) : error C2065: ‘d‘ : undeclared identifier
D:\winshare\CBasis\practice\practice3.c(39) : error C2109: subscript requires array or pointer type
D:\winshare\CBasis\practice\practice3.c(40) : error C2109: subscript requires array or pointer type
D:\winshare\CBasis\practice\practice3.c(40) : error C2109: subscript requires array or pointer type
*/
/*将下面这段代码放在这个位置还是出现一样的编译报错。
D:\winshare\CBasis\practice\practice3.c(43) : error C2143: syntax error : missing ‘;‘ before ‘type‘
D:\winshare\CBasis\practice\practice3.c(44) : error C2143: syntax error : missing ‘;‘ before ‘type‘
D:\winshare\CBasis\practice\practice3.c(45) : error C2065: ‘a‘ : undeclared identifier
D:\winshare\CBasis\practice\practice3.c(46) : error C2065: ‘b‘ : undeclared identifier
*/
/*
char a[] = {‘a‘,‘b‘,‘c‘,‘d‘,‘e‘};
char b[] = "abcde";
printf("size of a[] is:%d\n",sizeof(a));
printf("size of b[] is:%d\n",sizeof(b));
*/
//下面这段同上面的测试一样,同样报错。
/* char c[][3] = {{ ‘a‘ , ‘b‘ , ‘c‘ },{ ‘d‘ , ‘e‘ , ‘f‘ },{ ‘g‘ ,‘h‘ , ‘j‘ },{ ‘k‘ , ‘h‘ , ‘l‘ }};
char *p = 0;
char d[][5] = {"abcd","efgh","ijkl","mnol"};
*/
printf("size of a[] is:%d\n",sizeof(a));
printf("size of b[] is:%d\n",sizeof(b));
printf("size of c[][] is:%d\n",sizeof(c));
printf("size of c[0] is:%d\n",sizeof(c[0]));
printf("size of c[0][0] is %d\n",sizeof(c[0][0]));
printf("size of char *p is %d\n",sizeof(p));
printf("size of d[] is %d\n",sizeof(d[0]));
printf("size of d[0][0] is %d\n",sizeof(d[0][0]));
system("pause");
return 0;
}
总结(得自网上):具体的我也测试过了。在Linux上用gcc编译可以通过。
经过测试发现
在VC中编译c程序,在一个大括号括起的范围内,如果变量声明放在了函数调用的后面,那么编译的时候就会报错:
syntax error : missing ‘;‘ before ‘type‘
然后你可以修改为把变量声明放在函数调用之前。就会顺利通过编译。
这个问题在vc编译c++程序,或者gcc编译c程序的时候都不会出现,仅仅在vc编译c程序的时候才会出现.
syntax error : missing ';' before 'type'