Variable name and scope 1

Variable name and scope 2

Variable name and scope 3

Arithmetic operator 1

Arithmetic operator 2

Relational Operators - 1

Relational Operators - 2

Logical Operators - 1

Logical Operators - 2

Assignment Operator - 1

Assignment Operator - 2

Increment Decrement Operator - 1

Increment Decrement Operator - 2

Conditional Operator - 1

Conditional Operator - 2

sizeof operator - 1

sizeof operator - 2

Bitwise operator - 1

Bitwise operator - 2

Operator precedence and associativity - 1

Operator precedence and associativity - 2

Operator precedence and associativity - 3

if statement - 1

if statement - 2

if else - 1

if else - 2

switch statement - 1

switch statement - 2

for loop - 1

for loop - 2

while loop - 1

while loop - 2

do while loop - 1

do while loop - 2

break and continue - 1

break and continue - 2

pointer - 1

pointer - 2

This section on C interview questions, tricky questions, and puzzles focuses on “Relational 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 “Relational operators” along with answers and/or explanations.

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

#include <stdio.h>

int main()

{

int x = 20, y = 10, z = 10;

int p;

p = y + z == x;

printf("%d", p);

return 0;

}

a) 10

b) Syntax Error

c) 1

d) 0

b) Syntax Error

c) 1

d) 0

Correct Answer : c

Explanation : Due to operator precedence the arithmetic operator is solved first, then relational , and at last assignment.

Explanation : Due to operator precedence the arithmetic operator is solved first, then relational , and at last assignment.

Q2:What will be the output of following C code? #include <stdio.h> int main() { int p = 100, q = 200, r = 300; if (r > q > p) printf("true"); else printf("not true"); return 0; }

a) true

b) not true

c) Compile Time Error

d) Runtime Error

b) not true

c) Compile Time Error

d) Runtime Error

Correct Answer : b

Explanation : Let us understand the condition inside the if . Since there are two greater than (>) operators in expression “r > q > p”, associativity of > is considered. Associativity of > is left to right. So, expression r > q > p is evaluated as ( (r > q) > p ) which is false.

Explanation : Let us understand the condition inside the if . Since there are two greater than (>) operators in expression “r > q > p”, associativity of > is considered. Associativity of > is left to right. So, expression r > q > p is evaluated as ( (r > q) > p ) which is false.

Q3:What will be the output? #include <stdio.h> void main() { int a=3,b=2; a=a==b==0; printf("%d,%d",a,b); return 0; }

a) 3,1

b) 3,2

c) 2,1

d) 1,2

b) 3,2

c) 2,1

d) 1,2

Correct Answer : d

Explanation : First a==b results in 0, then 0==0 results in 1, so 1 is assigned to a, and b remains 2.

Explanation : First a==b results in 0, then 0==0 results in 1, so 1 is assigned to a, and b remains 2.