#include<stdio.h>
struct s_{
int b;
}s;
int func1(s** ss){
*ss->a = 10;
}
int func(s* t){
func1(&t);
}
int main(){
s a;
func(&a);
printf("\n a : %d \n",a.b);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
尝试示例程序并使用o/p获取错误.
O/P:
[root@rss]# gcc d.c
d.c:6: error: expected ‘)’ before ‘*’ token
d.c:9: error: expected ‘)’ before ‘*’ token
d.c: In function ‘main’:
d.c:13: error: expected ‘;’ before ‘a’
d.c:14: error: ‘a’ undeclared (first use in this function)
d.c:14: error: (Each undeclared identifier is reported only once
d.c:14: error: for each function it appears in.)
Run Code Online (Sandbox Code Playgroud)
typedef声明结构别名所需的内容s.b而不是a.ss在func1.main在C为int main(void).
#include <stdio.h>
typedef struct s_{
int b;
}s;
void func1(s** ss){
(*ss)->b = 10;
}
void func(s* t){
func1(&t);
}
int main(void)
{
s a;
func(&a);
printf("\n a.b : %d \n", a.b);
return 0;
}
Run Code Online (Sandbox Code Playgroud)