About Question enthuware.ocajp.i.v7.2.944 :
Posted: Thu Mar 27, 2014 1:16 pm
I think I have found a mistake in the explanation for this question.
Chaining to use a value of a variable at the time of declaration is not allowed. Had b and c been already declared, it would have been valid. For example, the following is valid:
int b = 0, c = 0;
int a = b = c = 100;
Even the following is valid:
int b , c; //Not initializing b and c here.
int a = b = c = 100; //declaring a and initializing c, b, and a at the same time. Notice the order of initialization of the variables - c is initialized first, b is initialized next by assigning to it the value of c. Finally, a is initialized.
------ Okay, never mind. I see that the two pairs of lines go together in the explanation, iow two examples total not four.
Chaining to use a value of a variable at the time of declaration is not allowed. Had b and c been already declared, it would have been valid. For example, the following is valid:
int b = 0, c = 0;
int a = b = c = 100;
Even the following is valid:
int b , c; //Not initializing b and c here.
int a = b = c = 100; //declaring a and initializing c, b, and a at the same time. Notice the order of initialization of the variables - c is initialized first, b is initialized next by assigning to it the value of c. Finally, a is initialized.
------ Okay, never mind. I see that the two pairs of lines go together in the explanation, iow two examples total not four.