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.
@Ablaze said:
1 decade ago
Can anyone explain this????????
#include<stdio.h>
int main() {
int b,a=10;
b=a++ + a++;
printf("%d %d %d %d",b,a++,a,++a);
return 0;
}
its op in gcc compiler is 20 13 14 14
#include<stdio.h>
int main() {
int b,a=10;
b=a++ + a++;
printf("%d %d %d %d",b,a++,a,++a);
return 0;
}
its op in gcc compiler is 20 13 14 14
SanLakshmi said:
1 decade ago
int b,a=10;
b=a++ + ++a;
printf("%d %d %d %d",b,a++,a,++a);
For this code i get the output as 22 13 13 13..
But i can't understand the real execution..
Anyone can explain?..
b=a++ + ++a;
printf("%d %d %d %d",b,a++,a,++a);
For this code i get the output as 22 13 13 13..
But i can't understand the real execution..
Anyone can explain?..
Siva said:
1 decade ago
@Shashanka.
a = 10;
Step1:
a++ = 11; (now a=11);
Step2:
++a = 11+1=12; (now a=12);
Step3:
++a = 12+1=13;
So the result is 11+12+13=36;
And then finally you got 36.
a = 10;
Step1:
a++ = 11; (now a=11);
Step2:
++a = 11+1=12; (now a=12);
Step3:
++a = 12+1=13;
So the result is 11+12+13=36;
And then finally you got 36.
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?
Kamlesh yadav said:
8 years ago
int x=3,y,z;
z=y=x;
z=y+=x=-z;
printf("%d%d%d",x,y,z);
For this code, I get the output as -3 0 0.
But, I can't understand the real execution.
Anyone can explain?
z=y=x;
z=y+=x=-z;
printf("%d%d%d",x,y,z);
For this code, I get the output as -3 0 0.
But, I can't understand the real execution.
Anyone can explain?
Zee khan said:
8 years ago
The above program or logical operation output is 35 because prefix first increment then print and postfix first print then increment. They use one postfix and two prefix.
Kumar said:
2 decades ago
Hi Sivaram,
Since C uses left associativity, to break up the tie between * / in the given expression z = x + y * z / 4 % 2 - 1 chooses the * first.
Since C uses left associativity, to break up the tie between * / in the given expression z = x + y * z / 4 % 2 - 1 chooses the * first.
Adi said:
8 years ago
What is the output of the following program?
void f1(){
static int s=5;
++s;
printf("%d",s);
}
main(){
f1();
f1();
printf("%d",s);
void f1(){
static int s=5;
++s;
printf("%d",s);
}
main(){
f1();
f1();
printf("%d",s);
Sri said:
10 years ago
When I tried to compile the following exp in gcc i.e.
main()
{
int a;
a=3/2*2;
printf("%d",a);
}
It gives me the answer as 2 how to solving this?
main()
{
int a;
a=3/2*2;
printf("%d",a);
}
It gives me the answer as 2 how to solving this?
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?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers