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
* / % + - =
= * / % + -
/ * % - + =
* % / - + =
Answer: Option
Explanation:
C uses left associativity for evaluating expressions to break a tie between two operators having same precedence.
Discussion:
92 comments Page 3 of 10.

LightYagami said:   9 years ago
Can anyone explain me the question?

main()
{
int a=1,b=2,c=3;
printf("%d",a+=(a+=3,5,a));
}

Answer is 8.

Sorna said:   9 years ago
@ALL.

#include<stdio.h>

int main()
{
int a=5;
int b=++a*a++;
printf("%d",b);
return 0;
}

Answer is 36.

Chris said:   9 years ago
According to me, it is;

int main().
int a=5
Int b=++a*a++
Print(%d,b)

Rajoo said:   9 years ago
Anybody, explain me the answer of this question. please.

Rakesh kumar said:   9 years ago
@Jaya.

a=4;
Printf("...d",a=a++)
Ans- here a++ is in post increment that's why it will change its value in next step but here there is no any next step that's what it will print the original value of a which is 4.
And in Printf(",,...d",a).


There is no any condition for value change so it will print its real value which is 4.
That's why both answers will be 4

Garima said:   9 years ago
% /*+-= is hierchie.

Jay Mehta said:   9 years ago
#include<stdio.h>

int main()
{
int a=5;
int b=++a*a++;
printf("%d",b);
return 0;
}

Can anyone tell me the answer of this?

Ravi Kumar said:   8 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).

Vaishali said:   7 years ago
@Mauli.
For your program.

The execution like this,
1) b+=++a which is equal to b=b+ ++a i.e b=20+11=31(stored in memory b=31 and a=11)
2) ++b=32( stored in memory).
3) a++=11( a=12 stored in memory now).
4) a+=b++ which is equal to a=a+ b++ i.e a=12+ 32=44( stored in memory a=44 and b=33 Because b++ is 1st assign then store in memory).

So the output is b=33 and a=44.

Jahnavi said:   7 years ago
In don't understand the answer can anyone please explain it clearly?


Post your comments here:

Your comments will be displayed after verification.