Here is a listing of C test questions on “Assignment Operators & Expressions” along with answers, explanations and/or solutions:
1. What is the type of the following assignment expression if x is of type float and y is of type int?
y = x + y;
a) int
b) float
c) there is no type for an assignment expression
d) double
Answer: a
Clarification: None.
2. What will be the value of the following assignment expression?
(x = foo())!= 1 considering foo() returns 2
a) 2
b) True
c) 1
d) 0
Answer: a
Clarification: None.
3. Operation “a = a * b + a” can also be written as ___________
a) a *= b + 1;
b) (c = a * b)!=(a = c + a);
c) a = (b + 1)* a;
d) All of the mentioned
Answer: d
Clarification: None.
4. What will be the final value of c in the following C statement? (Initial value: c = 2)
a) c = 1;
b) c = 2;
c) c = 3;
d) c = 4;
Answer: d
Clarification: None.
5. What will be the output of the following C code?
-
#include
-
int main()
-
{
-
int a = 1, b = 2;
-
a += b -= a;
-
printf("%d %d", a, b);
-
}
a) 1 1
b) 1 2
c) 2 1
d) 2 2
Answer: c
Clarification: None.
6. What will be the output of the following C code?
-
#include
-
int main()
-
{
-
int a = 4, n, i, result = 0;
-
scanf("%d", n);
-
for (i = 0;i < n; i++)
-
result += a;
-
}
a) Addition of a and n
b) Subtraction of a and n
c) Multiplication of a and n
d) Division of a and n
Answer: c
Clarification: None.
7. Which of the following is an invalid assignment operator?
a) a %= 10;
b) a /= 10;
c) a |= 10;
d) None of the mentioned
Answer: d
Clarification: None.