3 ms·
#include <stdio.h> struct abc { int a; int b; int c; }; int main() { struct abc b = {2}; printf("a b c = %d %d %d\n ", b.a, b.b, b.c); return 0; } %
by droithomme 8y ago
#include <stdio.h>
struct abc { int a; int b; int c; };
int main() {
struct abc b = {2};
printf("a b c = %d %d %d\n ", b.a, b.b, b.c);
return 0;
}
% c99 test.c
% a.out
a b c = 2 0 0
- klingonopera 8y agoAbsolutely! This is why I'll iterate through all and manually set each and every single element. You can even do it in one line, too: for (unsigned int i = 0; i < 3; i++) {b[i] = 2;} EDIT: Just noticed your code example uses structs. My example is for arrays, for which these observations are also correct.
- johnisgood 8y agohttps://stackoverflow.com/questions/10828294/c-and-c-partial-initialization-of-automatic-structure https://stackoverflow.com/questions/10828294/c-and-c-partial... > The C and C++ standards guarantee that even if an integer array is located on automatic storage and if there are fewer initializers in a brace-enclosed list then the uninitialized elements must be initialized to 0. It does work for zero-initialization.