Following code gives correct output, If I declare variables i
and j
, Like int i, j;
class A
{
int i, j;
public:
A(int val) : i(val), j(i + 1)
{
cout<<i<<endl<<j<<endl;
}
};
But If I declare variable i
and j
, like int j, i;
. then j
print garbage value.
class A
{
int j, i;
public:
A(int val) : i(val), j(i + 1)
{
cout<<i<<endl<<j<<endl;
}
};
So, Is it depend on order of declaration of variables?