Multiple Choice Questions and Answers for Assigment Operators & Expressions in C Language

https://www.computersprofessor.com/2017/09/multiple-choice-questions-and-answers_24.html
1. What is the output of this C code?
#include
void main()
{
int x = 0;
if (x = 0)
printf("Its zero\n");
else
printf("Its not zero\n");
}
a) Its not zero
b) Its zero
c) Run time error
d) None
b) Its zero
c) Run time error
d) None
Answer:a
2. What is the output of this C code?
#include
void main()
{
int k = 8;
int x = 0 == 1 && k++;
printf("%d%d\n", x, k);
}
a) 0 9
b) 0 8
c) 1 8
d) 1 9
b) 0 8
c) 1 8
d) 1 9
Answer:b
3. What is the output of this C code?
#include
void main()
{
char a = 'a';
int x = (a % 10)++;
printf("%d\n", x);
}
a) 6
b) Junk value
c) Compile time error
d) 7
b) Junk value
c) Compile time error
d) 7
Answer:c
4. What is the output of this C code?
#include
void main()
{
1 < 2 ? return 1: return 2;
}
a) returns 1
b) returns 2
c) Varies
d) Compile time error
b) returns 2
c) Varies
d) Compile time error
Answer:d
5. What is the output of this C code?
#include
void main()
{
unsigned int x = -5;
printf("%d", x);
}
a) Run time error
b) Aries
c) -5
d) 5
b) Aries
c) -5
d) 5
Answer:c
6. What is the output of this C code?
#include
int main()
{
int x = 2, y = 1;
x *= x + y;
printf("%d\n", x);
return 0;
}
a) 5
b) 6
c) Undefined behaviour
d) Compile time error
b) 6
c) Undefined behaviour
d) Compile time error
Answer:b
7. What is the output of this C code?
#include
int main()
{
int x = 2, y = 2;
x /= x / y;
printf("%d\n", x);
return 0;
}
a) 2
b) 1
c) 0.5
d) Undefined behaviour
b) 1
c) 0.5
d) Undefined behaviour
Answer:a
8. What is the output of this C code?
#include
int main()
{
int x = 1, y = 0;
x &&= y;
printf("%d\n", x);
}
a) Compile time error
b) 1
c) 0
d) Undefined behaviour
b) 1
c) 0
d) Undefined behaviour
Answer:a
9. What is the type of the below assignment expression if x is of type float, y is of type int?
y = x + y;
a) int
b) float
c) There is no type for an assignment expression
d) double
y = x + y;
a) int
b) float
c) There is no type for an assignment expression
d) double
Answer:a
10. What is the value of the below assignment expression
(x = foo())!= 1 considering foo() returns 2
a) 2
b) True
c) 1
d) 0
(x = foo())!= 1 considering foo() returns 2
a) 2
b) True
c) 1
d) 0
Answer:a
11. 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
a) a *= b + 1;
b) (c = a * b)!=(a = c + a);
c) a = (b + 1)* a;
d) All of the mentioned
Answer:d
12. for c = 2, value of c after c <<= 1;
a) c = 1;
b) c = 2;
c) c = 3;
d) c = 4;
Answer:d [/expand]
13. What is the output of this 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
b) 1 2
c) 2 1
d) 2 2
Answer:c
14. What is the output of this 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.
b) Subtraction of a and n.
c) Multiplication of a and n.
d) Division of a and n.
Answer:c
15. Which of the following is an invalid assignment operator?
a) a %= 10;
b) a /= 10;
c) a |= 10;
d) None of the mentioned
a) a %= 10;
b) a /= 10;
c) a |= 10;
d) None of the mentioned
Answer:d