First case:
class x
{
public:
x(){}
int mem;
}
Second case:
class x
{
public:
int mem;
}
int main()
{
x a;
std::cout << a.mem; //member not initialized error in second case
}
If we do not define the default constructor, the compiler will add one; and the function of the constructor is initializing the memory. So why is it giving an error in the second case, but not in the first case?