I wrote the following code snippet:
void foo() { struct _bar_ { int a; } bar; cout << \"Value of a is \" << bar.a; } <
Is it true to say that data members of a struct in c++ are always initialized by default (compared to c)? Or is the observed result just coincidence?
It is a coincidence.
Your code invokes Undefined Behavior; unless you explicitly set the members to 0 they can be anything.
0