Here is a listing of C Objective Questions on “Relational & Logical Operators” along with answers, explanations and/or solutions:
1. What will be the output of the following 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
Answer: a
Clarification: None.
2. What will be the output of the following 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
Answer: b
Clarification: None.
3. What will be the output of the following 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
Answer: c
Clarification: None.
4. What will be the output of the following C code?
-
#include -
void main()
-
{ -
int x = 1, z = 3;
-
int y = x << 3;
-
printf(" %dn", y);
-
}
a) -2147483648
b) -1
c) Run time error
d) 8
Answer: d
Clarification: None.
5. What will be the output of the following 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
Answer: a
Clarification: None.
6. What will be the final value of j in the following C 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
Answer: a
Clarification: None.
7. What will be the final value of j in the following C 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
Answer: a
Clarification: None.
8. What will be the output of the following C code?
-
#include -
int main()
-
{ -
int i = 1;
-
if (i++ && (i == 1))
-
printf("Yesn");
-
else -
printf("Non");
-
}
a) Yes
b) No
c) Depends on the compiler
d) Depends on the standard
Answer: b
Clarification: None.
