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 8 of 10.

YOUNI said:   8 years ago
What will be the value of sum after the following nested for loops are executed?
for i < 5

Please tell me the answer.

Draj said:   8 years ago
35 is the answer 10 + 12 + 13.

Mohammed said:   8 years ago
The answer is 35 on mac @Shashanka.

Ahmed said:   9 years ago
Can anyone solve this?

What is the output of the following?

a=23
b=34
puts a&b
puts a|b
puts a^b
puts ~a

Raji said:   9 years ago
{
int i=3,j=2,k=0,m;
m=++i || ++j && ++k
printf("%d %d %d %d",i,j,k,m);
}

Can anyone explain this solution, please?

Thanooja said:   9 years ago
% will have more precedence than *&/ ?

Lavanya said:   9 years ago
Thank you @Siva, I got clear answer.

Abhi said:   9 years ago
Why not option c? if as the same precedence.

Amala said:   9 years ago
C evaluates printf() statement from right to left.if we want to make it evaluates from left to write then we have declare the function to be PASCAL.

int b,a=10;
b=a++ + ++a;
printf("%d %d %d %d",b,a++,a,++a);

Output:
22, 13, 13

Kumar said:   9 years ago
What is the value of b if a=2;

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

Can explain this solution.


Post your comments here:

Your comments will be displayed after verification.