C Programming - Expressions - Discussion
Discussion Forum : Expressions - General Questions (Q.No. 1)
1.
Which of the following is the correct order of evaluation for the below expression?
z = x + y * z / 4 % 2 - 1
z = x + y * z / 4 % 2 - 1
Answer: Option
Explanation:
C uses left associativity for evaluating expressions to break a tie between two operators having same precedence.
Discussion:
92 comments Page 2 of 10.
Sharmin ferdoush said:
7 years ago
#include<stdio.h>
main()
{
int x=5,y=6;
x=++y;
y++=x--;
x++=6+(++y);
printf("%d%d\n",x++,y);
}
Anyone explain it, please.
main()
{
int x=5,y=6;
x=++y;
y++=x--;
x++=6+(++y);
printf("%d%d\n",x++,y);
}
Anyone explain it, please.
Akil Prakash said:
7 years ago
I am not getting this. Please anyone explain me.
Deepa said:
7 years ago
Hi @Diwakar.
Your answer is incorrect. x and y values are 24.
The increment and decrement operators are performing right to left. So at first ++i became 6, ++i is 7and ++i is 8. At last, a assign to 8. So there 3 'a's. So it will be 8+8+8=24 is assigned to b.
Your answer is incorrect. x and y values are 24.
The increment and decrement operators are performing right to left. So at first ++i became 6, ++i is 7and ++i is 8. At last, a assign to 8. So there 3 'a's. So it will be 8+8+8=24 is assigned to b.
Bollobhai deepa said:
7 years ago
Hi @Srivastava.
Here the increment and decrement operator's are performs depending upon the type of complier as if it is in turbos then the output is 42.
a=14;
Here b=(++a)+(a++)+(--a);
The operation for increment and decrement is right to left.
So first --a will be done. Now a will becomes 13 .and a++ is 13 only and at last a will be 14 for ++a.
Here a value is 14, so 14 +14 +14=42(here we have 3 a value )and 42 is assigned to b.
Here the increment and decrement operator's are performs depending upon the type of complier as if it is in turbos then the output is 42.
a=14;
Here b=(++a)+(a++)+(--a);
The operation for increment and decrement is right to left.
So first --a will be done. Now a will becomes 13 .and a++ is 13 only and at last a will be 14 for ++a.
Here a value is 14, so 14 +14 +14=42(here we have 3 a value )and 42 is assigned to b.
Ambrisha srivastava said:
7 years ago
Here;
int a=14,b;
b=(++a)+(a++)+(--a);
Give the value of a,b;
I got the outpu 45, other PC 42 .
Please explain to me.
int a=14,b;
b=(++a)+(a++)+(--a);
Give the value of a,b;
I got the outpu 45, other PC 42 .
Please explain to me.
Ravi Kumar said:
7 years ago
Hi @Sakib,
According to me, when you did not assign any value to a variable then it will print 0.
So, in this program, it will give output (0).
According to me, when you did not assign any value to a variable then it will print 0.
So, in this program, it will give output (0).
Sakib said:
7 years ago
#include<stdio.h>
int main (){
int a = 5, b = 6,c = 7, d = 8, e;
d = (a++) + (--b) + (++c)-(d--);
printf("%d", e);
return 0;
}
How it work?
int main (){
int a = 5, b = 6,c = 7, d = 8, e;
d = (a++) + (--b) + (++c)-(d--);
printf("%d", e);
return 0;
}
How it work?
Diwakar said:
7 years ago
#include<stdio.h>
int main(){
int i=5,j=5,y,x;
x=++i + ++i + ++i;
y=++j + ++j + ++j;
printf("%d %d %d %d",x,y,i,j);
return 0;
}
Explain me, how x&y came as 22 instead of 21?
int main(){
int i=5,j=5,y,x;
x=++i + ++i + ++i;
y=++j + ++j + ++j;
printf("%d %d %d %d",x,y,i,j);
return 0;
}
Explain me, how x&y came as 22 instead of 21?
Mithra said:
7 years ago
Hi,
int a=10.
Then pre-decrement perform.
We got --a=9.
Then post increment perform.
We got ++a=11.
Then add two value b=9+11.
int a=10.
Then pre-decrement perform.
We got --a=9.
Then post increment perform.
We got ++a=11.
Then add two value b=9+11.
Gaurav said:
7 years ago
int a=10;
b=--a + ++a;.
Output of b is 20 how?
b=--a + ++a;.
Output of b is 20 how?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers