Please Turn On Java Script To Access This Site.

C Institute | Questions

Previous Topic : Bitwise operator - 2Next Topic : Operator precedence and associativity - 2

This section focuses on C interview questions, tricky questions, and puzzles, and viva questions based on “operator precedence and associativity”. 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. It will improve their understanding of C Language. Here is a listing of C questions and puzzles on “operator precedence and associativity” along with answers and/or explanations.

Q1: Which operators of the following have same precedence?

A) !=
B) +=
C) <<=
a)  A and B
b)  A and C
c)  A,B and C
d)  B and C
Correct Answer : d
Explanation : The B and C are assignment operators, so they have the same precedence while A is relational operator, which have higher precedence than the assignment operator.
Learn c in depth

Q2: What will be the output of following c code?
#include <stdio.h>
void main()
	int a=10,b=2,x=0;
	printf("Value is =%d",x);
a)  Value is =650
b)  Value is =30
c)  Value is =80
d)  None of these
Correct Answer : c
Explanation : The order of solution of operator will be as follows
1. * 2. / 3.* 4.+ 5. + 6.=
Understand operator precedence and associativity here

Q3: What will be the value of a?
#include <stdio.h>
int main()
{   int a;    
    a = 10, 20, 30;
    printf("%d", a);    
    return 0;
a)  30
b)  20
c)  10
d)  Syntax Error
Correct Answer : c
Explanation : Here comma acts as an operator. The assignment operator has higher precedence than comma operator. So, the expression is considered as (a = 10), 20, 30 and 1 gets assigned to variable a.
Learn c from scratch

Previous Topic : Bitwise operator - 2Next Topic : Operator precedence and associativity - 2