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
--
对对一个元素进行赋值,其他元素置为默认的值;
对于C++中的结构体应该和java中的类一样,成员变量也对应着默认的初始化数值。
参考网页:http://cpp.wgets.com/thread/32174