This is in continuation with Strange behaviour of structures in C++ part 1
If I do this
#include<iostream>
using namespace std;
struct box
{
//int simple_int;
int arr[3];
};
int main()
{
box a={10,20,30};
//box b={100};
//cout<<b.simple_int<<"\n";
cout<<a.arr[0];
}
OUTPUT : 10 which is correct.
But if i remove the comments.
#include<iostream>
using namespace std;
struct box
{
int simple_int;
int arr[3];
};
int main()
{
box a={10,20,30};
box b={100};
cout<<b.simple_int<<"\n";
cout<<a.arr[0];
}
OUTPUT: 100 20 //instead of 100 10
Why?