Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

q20) CONSIDER THE FOLLOWING CODE: void Question_Eighteen() { string table = \"{

ID: 3810047 • Letter: Q

Question

q20)

CONSIDER THE FOLLOWING CODE:
void Question_Eighteen()
{
      string table = "{ { 1, 2 }, { 3, 4 }, { 5, 6 } }";
      int a = 5;
      int b = 5;
      if (b++ == ++a)
            cout << "the same b = " << b << " while a = " << a << endl;
      else
            cout << "not the same b = " << b << " while a = " << a << endl;
}

Select one:

a. the same b = 6 while a = 5

b. not the same b = 6 while a = 6

c. the same b = 6 while a = 6

d. not the same b = 5 while a = 6

please explain how you get the answer. Thank you

Explanation / Answer

Answer is B.

first a=5 and b=5

at the time of executing if statement ,if(b++==++a),

value of b not changed,it is =5.

but value of a is changed to a= 6; (pre-increment operator, ++a).so the result of if condition is not valid, it goes to else statement to execute and to produce output.

after if() condition executed, value of b is updated to b=6; (due to post-increment operator b++).

and value of a is printed as a=6.

so the ouput is

not the same b=6 while a=6.