The Gateway to Computer Science Excellence
First time here? Checkout the FAQ!
0 votes
Q) What is the output of the following C Program fragment


int main()


int a = 4, b = 3;


return 0;



A) 7      B) 8             C) 9               D) Error
asked in Programming by Loyal (8k points) | 147 views

2 Answers

0 votes

If there is no space between the post increment and preincrement operators, then there will be an error. Else it will run as usual 

answered by Active (2.8k points)

Please see the source of question

@Sayan Bose,While executing the code the error which popped up was
"lvalue" required.
Yes if all the + are written one after the other(without any space) then compilation error is "Lvalue required" but I am not able to understand what a+++++b implies i.e. whether it has any significant meaning in programming.
@Sayan Bose,A slight modification. The code will work fine in the following manner:-


Parentheses set a priority. Executing this way the answer is 8.
0 votes
OPTION: B is correct.

The output of this program will be 8 as the unary increment operator works right to left so in the statement a+++++b it will first increment b to 4 and will then perform addition and after that will update a.


Initially, a=4, b=3;

in a++ + ++b, b will be 4 and a will remain 4, so addition will be 4+4=8. So the output will be 8.

After printf the value of a will become 5.
answered by (13 points)

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true

38,084 questions
45,574 answers
49,060 users