203k views
0 votes
Int a = 1; int b = 0; int c = -1; if ((b + 1) == a) { b++; c += b; } if (c == a) { a--; b = 4; }

User Cesards
by
2.8k points

1 Answer

4 votes

Answer:


a = 1


b = 1


c = 0

Step-by-step explanation:

Given

The above code segment

Required

The final values of
a,\ b\ \&\ c

The following line declares and initializes the values of a, b and c

int a = 1; int b = 0; int c = -1;

So, we have:


a = 1; b =0; c = -1

Next, the following if condition is tested

if ((b + 1) == a)


b + 1 =0 +1


b + 1 = 1

And:


a = 1

So,


b + 1 = a = 1

Since the condition is true, the statements in the curly brace { } will be executed;


b++ \to b = b+1 \to b = 0 + 1 \to b = 1

So:


b = 1


c += b \to c = c+b \to c = -1 + 1 \to c = 0

So:


c = 0

Next, the following if condition is tested

c == a

c = 0 and a =1

So:


c \\e a

That means, the statements in its curly brace will not be executed.

So, the final values of a, b and c are:


a = 1


b = 1


c = 0

User TigOldBitties
by
3.4k points