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

Anjaneyagouda said:   8 years ago
If a=i*(j/=k/i) if a=5, i=2, j=3, k=4, how to solve this?

Babatunde said:   8 years ago
a = 1; a = a++; What is the current value of a?

Shahab said:   8 years ago
I have a question what will be this program output? Can anyone tell me?


#include <stdio.h>
int main()
{
int a = 2, b= 5, c = 10;
int x = 3, y = 6;
int res1 = a * b++ - (a * ++c) % b-- + c++ * a++;
int res2 = x++ * ++y;
printf("%d\n", res1);
printf("%d\n", res2);
return 0;

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);

Sriramprashad said:   8 years ago
Evaluate the following expression according to hierarchical rule, so the order of the evaluation and find the resultant data type of the expression.

int x= 2, y=30;
long l=10000;
double d=8.500;
x++ - (y-- /10) * ++x%y +l -(l+d,x--,++y) +!(d);.

Sriramprashad said:   8 years 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.
Can anyone explain?

Answer:-

b= a++ + ++a ( use and change + change and use)
b= 10 + 12 = 22 ( because a=10 used and incremented by 1 to 11 , incremented by 1 and changed to 12)
a++= 12 ( use and change current value value is 12 and incremented by 1 to 13
a=13
++a = 14 (change and use) current value is 13 and incremented by 1 to 14.

Output should be ( 22,12,13,14).

ANEESH said:   8 years ago
Please expalin me q=int(a); expression.

int main (void)
{
float a;
int q;

printf("\nInsert number\t");
scanf("%f",&a);

q=(int)a;
++q;

if((q - a) != 1)
printf("\nThe number is not an integer\n\n");
else
printf("\nThe number is an integer\n\n");

return 0;
}

ANEESH said:   8 years ago
Can you explain it?

int main (void)
{
float a;
int q;

printf("\nInsert number\t");
scanf("%f",&a);

q=(int)a;
++q;

if((q - a) != 1)
printf("\nThe number is not an integer\n\n");
else
printf("\nThe number is an integer\n\n");

return 0;
}

LightYagami said:   8 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:   8 years ago
@ALL.

#include<stdio.h>

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

Answer is 36.


Post your comments here:

Your comments will be displayed after verification.