1,837 views

4 Answers

0 0 votes

Answer is 20

Explaination :

 

so a= 6+6+8 = 20

 

0 0 votes
The answer will be

a =21

While all the calls are on the same line then increment will be done on every call.so in first call a=6, in second a=7 and in third call a=8.
0 0 votes

Rule 1 : unary having higher precedence than binary : So lets solve all unary first then take binary

Rule 2: The precedence of post-increment is significantly higher than that of pre-increment in C. Furthermore, when it comes to associativity, pre-increment has right-to-left associativity, whereas post-increment has left-to-right associativity.

Ref: https://www.upgrad.com/tutorials/software-engineering/c-tutorial/pre-increment-and-post-increment-in-c/#:~:text=The%20precedence%20of%20post%2Dincrement,left%2Dto%2Dright%20associativity.

a=5

a= ++a + (a++) + ++a; [post increment higher]

a= ++a + 6 + (++a); [pre increment right to left associativity]

a=  (++a) + 6 + 7;

a= 8 + 6 + 7;

a= 21

So the ans is 21.

Open for any corrections

Position:
Show:

Related questions

0 0 votes
3 answers 3 answers
848
848 views
shivamSK asked Jun 8, 2024
848 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")...
0 0 votes
1 answers 1 answer
844
844 views
Nandkishor3939 asked Jan 13, 2019
844 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(){...
0 0 votes
2 2 answers
3.7k
3.7k views
Lakshman Bhaiya asked Apr 21, 2018
3,719 views
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 ...
0 0 votes
0 0 answers
601
601 views
rahul sharma 5 asked Aug 25, 2017
601 views
What is the input and output of increment/decrement operator in the C language in terms of rvalue and lvalue?