0

What is output of the 👇 code

Give answer in detail how it comes If you like code upvote me https://code.sololearn.com/c7QWOPAmVgJP/?ref=app

25th Dec 2020, 2:31 PM
Yadvendra Garg
Yadvendra Garg - avatar
7 odpowiedzi
+ 2
You're welcome, And it is good question BTW Stay curious 👍
25th Dec 2020, 4:11 PM
Ipang
0
It becomes easier to read and understand if you put spaces in between printf("%d \n", a++ + b); `a++` is post-increment operation, meaning it does not take effect immediately, until statement end (semicolon), or another post/pre increment is applied to variable <a>. But mixing up access and modification to a certain data in one statement is not such good idea.
25th Dec 2020, 2:49 PM
Ipang
0
But it canbe like : a + ++b How can you say it must be like a++ + b
25th Dec 2020, 2:54 PM
Yadvendra Garg
Yadvendra Garg - avatar
0
Excuse me, when did I say it *must be* like `a++ + b`? You will get different result if you write `a + ++b` because this way pre-increment operator is applied on variable <b>. The way your code was written (`a+++b`) compiler will take it as `a++ + b` because operator precedence plays a role there https://en.cppreference.com/w/c/language/operator_precedence
25th Dec 2020, 3:02 PM
Ipang
0
Sorry for this But when try to compile it always give answer 7 So my question is that why compiler read it as a++ + b why not a + ++b
25th Dec 2020, 3:34 PM
Yadvendra Garg
Yadvendra Garg - avatar
0
It's because post-increment operator has higher precedence (priority) opposed to pre-increment operator. Read the linked page to see clearly.
25th Dec 2020, 3:42 PM
Ipang
0
Ok thank you
25th Dec 2020, 3:59 PM
Yadvendra Garg
Yadvendra Garg - avatar