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 4 of 10.
Medss said:
7 years ago
Int a=1 ,b=2,c=3
Switch (p)
{
Case1:a++
Case2:++b
Break;
Case 3:c--;
}
System.out.println(a+","+b+","+c);
When 1:p=1 2:p=3.
Switch (p)
{
Case1:a++
Case2:++b
Break;
Case 3:c--;
}
System.out.println(a+","+b+","+c);
When 1:p=1 2:p=3.
Mauli said:
7 years ago
#include<stdio.h>
main()
{
int a=10,b=20;
b+=++a;++b;a++;
a+=b++;
printf("a=%d \n b=%d",a,b);
}
a=44
b=33
Please explain this program.
How b=33 and a=44?
main()
{
int a=10,b=20;
b+=++a;++b;a++;
a+=b++;
printf("a=%d \n b=%d",a,b);
}
a=44
b=33
Please explain this program.
How b=33 and a=44?
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.
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.
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.
Nilay tagde said:
8 years ago
When this *for*loop will terminate?
for(a=1;scanf("%d",&a);a++)
printf("%d",a);
for(a=1;scanf("%d",&a);a++)
printf("%d",a);
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?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers