C中结构体赋值问题一直没有很清楚,下面发了一个讨论的帖子,自己写了个简单的例程测了下:
#include <stdio.h>
struct test{
int a;
int b;
char c;
float d;
};
int main(){
struct test test_num = {0};
printf("a = %d ,b = %d ,c = %c ,d = %f/n" , test_num.a ,test_num.b ,test_num.c ,test_num.d);
struct test test_num1 = {1};
printf("a = %d ,b = %d ,c = %c ,d = %f/n" , test_num1.a ,test_num1.b ,test_num1.c ,test_num1.d);
}
a = 0 ,b = 0 ,c = ,d = 0.000000
a = 1 ,b = 0 ,c = ,d = 0.000000
参考网页:http://cpp.wgets.com/thread/32174
本文通过一个简单的C语言示例程序探讨了结构体初始化时各成员变量如何被赋值的问题。当只对部分成员变量赋值时,其余成员将采用默认值。此行为与C++中的结构体初始化类似。
1586

被折叠的 条评论
为什么被折叠?



