what will be the output of the follwing C code??

int i=5;
int b=++i+++i+++i;
printf("%d",b);

please mention the explanation also.....
Asked by
CpjJwWHV   compilation error
14 years ago
CpjJwWHV   compile error becoz some compiler not recognize this at syntatically true;
14 years ago
CpjJwWHV   it will show compilation error .
14 years ago
CpjJwWHV   it vl give compile time error.....as compiler may get confuse which is increment operator and which is addition operator.
14 years ago
CpjJwWHV   i guess it will show lvalue error..
14 years ago
CpjJwWHV   yr right deepak its lvalue error i have run it....
14 years ago
CpjJwWHV   int i=5;
int b=++i + ++i + ++i;
printf("%d",b);


output - > 22
14 years ago
CpjJwWHV    int i=5;
int b=++i + ++i + ++i;
printf("%d",b);

for like this the o/p is 21

void main()
{
int i=5;
int b=++i+++i+++i;
printf("%d",b);

}

for this compilation error.
14 years ago
CpjJwWHV   int b=5;
int b=++i + ++i + ++i;
printf("%d",b);

for this o/p --> 22 NOT 21,

int i=5;
int b=++i+++i+++i;
printf("%d",b);
for this compilation error bcoz when scanning is done by compiler,it is confused whether (consider middle i -- > +++i+++)++ i is used or i++ used for increment,at a time compiler can done 1 modification so error
14 years ago
CpjJwWHV   answer will be 24
14 years ago
CpjJwWHV   @ankush no ,compile it then see the result,

what will be the o/p -- >
int i = 5;
int b= ++i + ++i + ++i + ++i;
printf("%d",b);
14 years ago
CpjJwWHV   i have compiled it and i also know the usage of++i,u better check it and recompile it(dheerender)

14 years ago
CpjJwWHV   @ankush i am also getting 24 bt how..???
14 years ago
CpjJwWHV   the answer is 24.....there r 3 pre increment....so the value becomes 8 of I.....then it is assigned to all tree position of I....so 8+8+8=24...
14 years ago
CpjJwWHV   ya joy has explained it correctly...
14 years ago
CpjJwWHV   thanks
14 years ago
CpjJwWHV   go to the link --- > http://ideone.com/
This is latest online compiler , u can compile ur code here and see ,result is 22 not 24,
14 years ago
CpjJwWHV   int i=5;
int b=++i + ++i + ++i;
printf("%d",b);
for thz output is 21
14 years ago
CpjJwWHV   hey the answer is not 21 always.it depends on compiler used.in gcc compiler ans is 22
14 years ago
CpjJwWHV   in TC its compile erroe as l value required.
14 years ago
CpjJwWHV   s output depends on cmpiler tooo
14 years ago

Smiley