in Programming in C retagged by
1,657 views
0 votes
0 votes

What is the value of $‘b’$ after the execution of the following code statements :

$C=10;$

$B=++c + ++c;$

  1. $20$                 
  2. $22$       
  3. $23$                 
  4. None
in Programming in C retagged by
1.7k views

2 Comments

none. Undefined behavior
0
0
Ans is 24
0
0

2 Answers

0 votes
0 votes
It will give compilation error .
–1 vote
–1 vote
23 is the answer

Case 1:

c=10;

b= ++c + ++c;

Then, b=11 + ++c (as ++c means 1st increment and then assignment, so c+1=10+1=11)

Then b= 11 + 12 (same as above)

So, b=23

Case 2:

c=10;

b= ++c++ +c;

Then, ++c means c value(10) at 1st increment then assignment , so 11 (++c) will get added to the value of c after c++ operation

Again c++ means 1st assignment then increment

After increment(i.e., c++), c =12

Now b=11+12 =23

2 Comments

you are wrong...it will give error or undefined behavior
1
1
Why the case 2 is wrong? Please explain
0
0

Related questions