Question #23966

2. What does the following code output?
int c = 4;
if (c % 2 == 0) {
c += 1;
}
cout << c << endl;

Expert's answer

int c = 4;
sets integer value c equal to 4;

if(c % 2 == 0) {
if c is divisible by 2

c += 1;
add 1 to c (so c is equal to 5)

cout<< c << endl;
outputs c on screen
LATEST TUTORIALS
APPROVED BY CLIENTS