Multiple Choice Questions and Answers for Relational & Logical Operators in C Language

https://www.computersprofessor.com/2017/09/multiple-choice-questions-and-answers_15.html
These questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate or an experienced IT professional. Our C Interview questions come with detailed explanation of the answers which helps in better understanding of C concepts.
Here is a listing of C interview questions on “Relational & Logical Operators” along with answers, explanations and/or solutions:
1. What is the output of this C code?
#include
void main()
{
int x = 1, y = 0, z = 5;
int a = x && y || z++;
printf("%d", z);
}
a) 6
b) 5
c) 0
d) Varies
b) 5
c) 0
d) Varies
Answer:a
2. What is the output of this C code?
#include
void main()
{
int x = 1, y = 0, z = 5;
int a = x && y && z++;
printf("%d", z);
}
a) 6
b) 5
c) 0
d) Varies
b) 5
c) 0
d) Varies
Answer:b
3. What is the output of this C code?
#include
int main()
{
int x = 1, y = 0, z = 3;
x > y ? printf("%d", z) : return z;
}
a) 3
b) 1
c) Compile time error
d) Run time error
b) 1
c) Compile time error
d) Run time error
Answer:c
4. What is the output of this C code?
#include
void main()
{
int x = 1, z = 3;
int y = x << 3;
printf(" %d\n", y);
}
a) -2147483648
b) -1
c) Run time error
d) 8
b) -1
c) Run time error
d) 8
Answer:d
5. What is the output of this C code?
#include
void main()
{
int x = 0, y = 2, z = 3;
int a = x & y | z;
printf("%d", a);
}
a) 3
b) 0
c) 2
d) Run time error
b) 0
c) 2
d) Run time error
Answer:a
6. What is the final value of j in the below code?
#include
int main()
{
int i = 0, j = 0;
if (i && (j = i + 10))
//do something
;
}
a) 0
b) 10
c) Depends on the compiler
d) Depends on language standard
b) 10
c) Depends on the compiler
d) Depends on language standard
Answer:a
7. What is the final value of j in the below code?
#include
int main()
{
int i = 10, j = 0;
if (i || (j = i + 10))
//do something
;
}
a) 0
b) 20
c) Compile time error
d) Depends on language standard
b) 20
c) Compile time error
d) Depends on language standard
Answer:a
8. What is the output of this C code?
#include
int main()
{
int i = 1;
if (i++ && (i == 1))
printf("Yes\n");
else
printf("No\n");
}
a) Yes
b) No
c) Depends on the compiler
d) Depends on the standard
b) No
c) Depends on the compiler
d) Depends on the standard
Answer:b
9. What is the output of this C code?
#include
void main()
{
int a = 3;
int b = ++a + a++ + --a;
printf("Value of b is %d", b);
}
a) Value of x is 12
b) Value of x is 13
c) Value of x is 10
d) Undefined behaviour
b) Value of x is 13
c) Value of x is 10
d) Undefined behaviour
Answer:d
10. The precedence of arithmetic operators is (from highest to lowest)
a) %, *, /, +, –
b) %, +, /, *, –
c) +, -, %, *, /
d) %, +, -, *, /
a) %, *, /, +, –
b) %, +, /, *, –
c) +, -, %, *, /
d) %, +, -, *, /
Answer:a
11. Which of the following is not an arithmetic operation?
a) a *= 10;
b) a /= 10;
c) a != 10;
d) a %= 10;
a) a *= 10;
b) a /= 10;
c) a != 10;
d) a %= 10;
Answer:c
12. Which of the following data type will throw an error on modulus operation(%)?
a) char
b) short
c) int
d) float
a) char
b) short
c) int
d) float
Answer:d
13. Which among the following are the fundamental arithmetic operators, ie, performing the desired operation can be done using that operator only?
a) +, –
b) +, -, %
c) +, -, *, /
d) +, -, *, /, %
a) +, –
b) +, -, %
c) +, -, *, /
d) +, -, *, /, %
Answer:a
14. What is the output of this C code?
#include
int main()
{
int a = 10;
double b = 5.6;
int c;
c = a + b;
printf("%d", c);
}
a) 15
b) 16
c) 15.6
d) 10
b) 16
c) 15.6
d) 10
Answer:a
15. What is the output of this C code?
#include
int main()
{
int a = 10, b = 5, c = 5;
int d;
d = a == (b + c);
printf("%d", d);
}
a) Syntax error
b) 1
c) 10
d) 5
b) 1
c) 10
d) 5
Answer: b