Here is a listing of online C test questions on “Precedence and Order of Evaluation” along with answers, explanations and/or solutions:
1. What will be the output of the following C code?
-
#include
-
void main()
-
{
-
int a = 5 * 3 + 2 - 4;
-
printf("%d", a);
-
}
a) 13
b) 14
c) 12
d) 1 6
Answer: a
Clarification: None.
2. What will be the output of the following C code?
-
#include
-
void main()
-
{
-
int a = 2 + 4 + 3 * 5 / 3 - 5;
-
printf("%d", a);
-
}
a) 7
b) 6
c) 10
d) 9
Answer: b
Clarification: None.
3. What will be the output of the following C code?
-
#include
-
void main()
-
{
-
int a = 5 * 3 % 6 - 8 + 3;
-
printf("%d", a);
-
}
a) 10
b) 2
c) -2
d) -3
Answer: c
Clarification: None.
4. What will be the output of the following C code?
-
#include
-
void main()
-
{
-
int b = 6;
-
int c = 7;
-
int a = ++b + c--;
-
printf("%d", a);
-
}
a) Run time error
b) 15
c) 13
d) 14
Answer: d
Clarification: None.
5. What will be the output of the following C code?
-
#include
-
void main(
-
{
-
double b = 8;
-
b++;
-
printf("%lf", b);
-
}
a) 9.000000
b) 9
c) 9.0
d) Run time error
Answer: a
Clarification: None.
6. What will be the output of the following C code?
-
#include
-
void main()
-
{
-
double b = 3 % 0 * 1 - 4 / 2;
-
printf("%lf", b);
-
}
a) -2
b) Floating point Exception
c) 1
d) 0
Answer: b
Clarification: None.
7. What will be the output of the following C code?
-
#include
-
void main()
-
{
-
double b = 5 % 3 & 4 + 5 * 6;
-
printf("%lf", b);
-
}
a) 2
b) 30
c) 2.000000
d) Run time error
Answer: c
Clarification: None.
8. What will be the output of the following C code?
-
#include
-
void main()
-
{
-
double b = 3 && 5 & 4 % 3;
-
printf("%lf", b);
-
}
a) 3.000000
b) 4.000000
c) 5.000000
d) 1.000000
Answer: d
Clarification: None.
9. What will be the output of the following C code?
-
#include
-
void main()
-
{
-
double b = 5 & 3 && 4 || 5 | 6;
-
printf("%lf", b);
-
}
a) 1.000000
b) 0.000000
c) 7.000000
d) 2.000000
Answer: a
Clarification: None.
10. What will be the output of the following C code?
-
#include
-
void main()
-
{
-
int k = 0;
-
double b = k++ + ++k + k--;
-
printf("%d", k);
-
}
a) 6
b) 1
c) 5
d) undefined
Answer: d
Clarification: None.