An example of second rank pointer struct data
1 #include <stdio.h>
2
3 void main()
4 {
5 struct cc{
6 int a;
7 char *ap;
8 };
9 struct cc c;
10 c.a=100;
11 c.ap="abcdefg\n";
12
13 printf("%d;%s",c.a,c.ap);
14
15 struct cc * cp=&c;
16 printf("%d;%s",cp->a,cp->ap);
17
18 struct cc ** cpp=&cp;
19 printf("%d,%s",(**cpp).a,(**cpp).ap);
20 printf("%d,%s",(*cpp)->a,(*cpp)->ap);
21 }
结果:
omycle@omycle-desktop:~/network$ ./test
100;abcdefg
100;abcdefg
100,abcdefg
100,abcdefg
2
3 void main()
4 {
5 struct cc{
6 int a;
7 char *ap;
8 };
9 struct cc c;
10 c.a=100;
11 c.ap="abcdefg\n";
12
13 printf("%d;%s",c.a,c.ap);
14
15 struct cc * cp=&c;
16 printf("%d;%s",cp->a,cp->ap);
17
18 struct cc ** cpp=&cp;
19 printf("%d,%s",(**cpp).a,(**cpp).ap);
20 printf("%d,%s",(*cpp)->a,(*cpp)->ap);
21 }
结果:
omycle@omycle-desktop:~/network$ ./test
100;abcdefg
100;abcdefg
100,abcdefg
100,abcdefg
评论
发表评论