3,730 views
0 0 votes
Q) What is the output of the following C Program fragment

#include<stdio.h>

int main()

{

int a = 4, b = 3;

printf("%d",a+++++b);

return 0;

}

 

A) 7      B) 8             C) 9               D) Error

2 Answers

0 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 

0 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.
Position:
Show:

Related questions

0 0 votes
0 0 answers
605
605 views
rahul sharma 5 asked Aug 25, 2017
605 views
What is the input and output of increment/decrement operator in the C language in terms of rvalue and lvalue?
0 0 votes
3 answers 3 answers
854
854 views
shivamSK asked Jun 8, 2024
854 views
answer the output#include <stdio.h int main() { int x=0; x++; if( x){ x=x++; if(x){ printf("hello"); }else{ printf("%d",x); } }else{ x=x+5; if(x){ printf("i win x times")...
2 2 votes
4 4 answers
1.8k
1.8k views
malaviya_parth asked Jan 15, 2024
1,844 views
#include <stdio.h int main() { int a = 5, b; a = ++a + a++ + ++a; printf("%d",a); return 0; }What will be the output of the code?
0 0 votes
1 answers 1 answer
852
852 views
Nandkishor3939 asked Jan 13, 2019
852 views
The output of this program comes out to be 0,Why not 1?Because: a=0;will be assigned then a++;So now 0 will be 1; a=1; This freaks me out !!#include <stdio.h>int main(){...