Computer Science - Object Oriented Programming Using C++ - Discussion

Discussion Forum : Object Oriented Programming Using C++ - Section 3 (Q.No. 4)
4.
If p and q are assigned the values 2 and 3 respectively then the statement p = q++
gives an error message
assigns a value 4 to p
assigns a value 3 to p
assigns a value 5 to p
None of the above
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
7 comments Page 1 of 1.

SADIQ said:   6 years ago
Here postfix increment is used. If the statement is "p=++q" then the answer must be 4. But here the right answer is 3.

Rup said:   6 years ago
Here, q is having post increment operator. So, 3 is assigned to p first. Then only q is incremented.

Sharon said:   7 years ago
I am afraid, the answer must be option B.

Because when q is declared as 3, here it is also given an operation "p=q++" which shows that there is an increment to be done. So obviously 3 must be incremented form 3 to 4 so the answer must be p=4.

Rama said:   8 years ago
As per to my knowledge assigning is occurs after initialization. But here the p = q++. q is initialized and then assigned to p.

The increment operator is post-fix. So at first the value is of p is 3.

Akram said:   8 years ago
Please explain how could you possible that I think right answer is B.

Vikas bansal said:   9 years ago
This is post increment operator, first value assigned and then increment occurs.

Biswajit borah said:   1 decade ago
Here value of q is first assigned to p that is 3 is assigned to 3 then The value is incremented to 4 by q++.

Post your comments here:

Your comments will be displayed after verification.