Recommended Answers
Jump to PostNested structure member initialization.
#include <stdio.h> struct test { char name[20]; int no; }; struct pop { struct test p; }; static struct test a={ .name="raj", .no=10 }; int main() { printf("\n%s %d",a.name,a.no); return 0; }
Jump to Posti couldn't understand the "." format...
It's one of the new features to C. You can initialize struct members by name instead of by position:
struct test { int first; int second; int third; }; struct test a = {0, 0, 1}; /* Old way */ struct …
Jump to Postyou don't have to initialize every member before the one you want to initialize. 0 is the default, so if I wanted to only initialize third, the old way is still the same but the new way is easier...
Wrong. Wrong. Wrong.
Structures, or any other variable, are not …
Jump to PostWrong. Wrong. Wrong.
Structures, or any other variable, are not initialized to zero or any other value "by default" ... just because your compiler happens to do so, does not mean someone else's compiler does.
this error is probably the single-most source of broken code, and endless debugging efforts.
thanks …
All 16 Replies
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.