2,525 views
0 votes
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 votes
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 votes
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.

Related questions

0 votes
0 votes
0 answers
1
rahul sharma 5 asked Aug 25, 2017
378 views
What is the input and output of increment/decrement operator in the C language in terms of rvalue and lvalue?
0 votes
0 votes
1 answer
2
0 votes
0 votes
3 answers
3
mamta beniwal asked Jun 13, 2018
563 views
if x=y=z=-1then the values of x,y,z after++x && ++y ||++z is shown as x=0,y=-1, and z=0 Please explain the reason behind this as I am not getting the reason of z=0.
0 votes
0 votes
3 answers
4
lalitver10 asked Oct 23, 2021
667 views
#include <stdio.h>int main(){ int a=20; int *ptr=&a; int x=a; printf ("%p\n",&*ptr); printf ("%p\n",&a); return 0;}Why both printf() line printing the s...