Vidyalelo
Computer Science · Q497

Object Oriented Programming Using C++

Engineering and GATE · Computer Science · question 497

Q497

The expression c = i++ causes

A.
the value of i assigned to c and then i incremented by 1
Answer
B.
i to be incremented by 1 and then the value of i assigned to c
C.
value of i assigned to c
D.
i to be incremented by 1
E.
None of the above

Answer: Option A

Solution

Answer: Option A
Solution:
The expression c = i++ is an example of the post-increment operator in C++.

In the post-increment operation, the current value of i is assigned to c first.

After this assignment, the value of i is incremented by 1.

Option A: the value of i assigned to c and then i incremented by 1 - This is correct because it accurately describes the post-increment behavior.

Option B: i to be incremented by 1 and then the value of i assigned to c - This is incorrect because it describes the pre-increment operation, not post-increment.

Option C: value of i assigned to c - This is incomplete because it doesn't mention the increment operation.

Option D: i to be incremented by 1 - This is incorrect because it doesn't mention the assignment to c.

Option E: None of the above - This is incorrect because Option A is correct.

Therefore, the correct answer is Option A: the value of i assigned to c and then i incremented by 1.