Machine-translated by Google. Questions are authored in English.
Top

Discussion

For the following statement find the values generated for p and q?

int p = 0, q = 1;
p = q++;
p = ++q;
p = q--;
p = --q;

Value of p & q are

  • A.1 1
  • B.0 0
  • C.3 2
  • D.1 2

Answer: A

Correct answer: 1 1

Follow the four statements from p = 0, q = 1:

  • p = q++; - p gets the old 1; q becomes 2.
  • p = ++q; - q becomes 3 and p gets 3.
  • p = q--; - p gets the old 3; q becomes 2.
  • p = --q; - q becomes 1 and p gets 1.

So both end at 1.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.