+ 1
How output is - 3?
3 Answers
+ 4
First u need to what prefix ++ and suffix ++ doing in background.
Prefix:
int a=6;
printf("%d %d",a++,a);
Output: 6 7
Reason:
Becoz when u use a++;
The compiler will first make a temprory variable to do the calculation like
temp= a;
temp=temp+1;
a=temp;
So when u use a++ on that step the value of (a) wont be changed.But after encountering a line break like semicolon in C it will change the value of (a) to 7.
Sufix:
int a=6;
Printf("%d%d",++a,a);
Output: 7 7
But when u use ++a it wont make a temprory variable like the previous one.Instead it change the statement like a=a+1;
So before encounter the line break the value of (a) is changed.
Thats it bro if u have any further clarification pls repl
đđđđ
+ 4
Everything in the parenthesis is operated first from left to right it is read like this
Int k=-5;
Int a=(k++,++k);
a= (-4,-3);
a=-3;
After reading everything inside parenthesis last value was -3 so its was assign to a and output is -3
+ 3
Sagar Singh dost in your program
Int K = (a++, ++a);
This is the reason of answer -3
If you enter a--, ++a ans = -5
++a, ++a ans =-3
--a , ++a ans = -5
a++, a++ ans = -4
if you add arithmetic operator like this
int k =(a++, a++); ans = -4
because last a++ will not increase value by 1
Buddy just play around with code and you will easily understand
I hope you get it