为何错了
为什么错了?#include stdio.hvoid Q1(struct TT k1)int main() {struct TT{int xchar y}a{1,A},b
为什么错了?
#include <stdio.h>
void Q1(struct TT k1);
int main()
{
struct TT{
int x;
char y;
}a={1,'A'},
b={2,'B'};
Q1(a);
return 0;
}
void Q1(struct TT k1)
{
printf("%d\n",k1.x);
printf("%d\n",k1.y);
}
z@z:~$ gcc -Wall a.c
a.c:3: warning: ‘struct TT’ declared inside parameter list
a.c:3: warning: its scope is only this definition or declaration, which is probably not what you want
a.c: In function ‘main’:
a.c:12: error: type of formal parameter 1 is incomplete
a.c:10: warning: unused variable ‘b’
a.c: At top level:
a.c:16: warning: ‘struct TT’ declared inside parameter list
a.c:16: error: parameter 1 (‘k1’) has incomplete type
z@z:~$
[解决办法]你把结构声明到外边,在函数内部的话 他的作用域就在main函数里面,外边的函数使用了未定义的数据类型