Please Turn On Java Script To Access This Site.

C Institute | Questions


Previous Topic : Relational Operators - 2Next Topic : Logical Operators - 2

This section on C interview questions, tricky questions, and puzzles focuses on “Logical operators”. One shall practice these questions and puzzles to improve their C programming skills needed for various interviews (campus interviews, walk-in interviews, viva exams and company interviews), placements, entrance exams and other competitive exams. These programming questions can be attempted by anyone focusing on learning C Programming language. They can be a beginner, fresher, engineering graduate, engineering student, bca student, mca student, mcs students or an experienced IT professional. Here is a listing of C questions and puzzles on “Logical operators” along with answers and/or explanations.

Q1: How many logical operators available in c?
a)  3
b)  4
c)  2
d)  1
Correct Answer : a
Explanation : C have three logical operators - &&, || , !


Q2: What will be the output of the following C code?

#include <stdio.h>
void main()
{
    int a = 100, b = 0, c = 500;
    int d = a && b || c++;
    printf("%d", c);
   
}
a)  1
b)  500
c)  501
d)  0
Correct Answer : c
Explanation : a && b results in 0, 0 || c++ results in 1, and c++ will increase the value of c by 1.


Q3: #include <stdio.h>
void main()
{
    int a = 100, b = 0, c = 500;
    int d = a || b || c++;
    printf("%d", c);
}
a)  1
b)  0
c)  500
d)  501
Correct Answer : c
Explanation : a || b yields 1, so due to short circuit, c++ will not be executed.


Q4: Are logical operators executed sequentially?
a)  True
b)  False
c)  Depends on compiler
d)  Depends on standard
Correct Answer : b
Explanation : The logical operators are not executed sequentially.


Q5: What will be the output of the following C code?

#include <stdio.h>
int main()
{
      int x = 100, y = 100, z = 300;
      x != !y;
      z = !!x;
      printf("%d %d", y, z);
      return 0;
}
a)  100 1
b)  1 1
c)  1 300
d)  100 300
Correct Answer : a


Q6: Which among the following is NOT a logical operator?
a)  !=
b)  !
c)  &&
d)  ||
Correct Answer : a
Explanation : != is a relational operator.


Q7: Which of the following is not a logical operator?
a)  &&
b)  |
c)  ||
d)  !
Correct Answer : b
Explanation : C have three logicaL operators, && – Logical AND, ! – Logical NOT, ||– Logical OR.
The symbol | is Bitwise OR (used in bitwise manipulations).


Previous Topic : Relational Operators - 2Next Topic : Logical Operators - 2