MCQ Computer Science

C Programming Questions and Answers – Precedence and Order of Evaluation – 1

C Programming Questions and Answers – Precedence and Order of Evaluation – 1

This section on C language interview questions and answers focuses on “Precedence and Order of Evaluation”. One shall practice these interview questions to improve their C programming skills needed for various interviews (campus interviews, walkin interviews, company interviews), placements, entrance exams and other competitive exams. 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 language interview questions come with detailed explanation of the answers which helps in better understanding of C concepts.
Here is a listing of C language interview questions “Precedence and Order of Evaluation” along with answers, explanations and/or solutions:

1. What is the output of this C code?

#include <stdio.h>
int main()
{
reverse(1);
}
void reverse(int i)
{
if (i > 5)
exit(0);
printf(“%d\n”, i);
return reverse(i++);
}
a) 1 2 3 4 5
b) 1 2 3 4
c) Compile time error
d) Stack overflow

View Answer

Answer:d

2. What is the output of this C code?

#include <stdio.h>
void reverse(int i);
int main()
{
reverse(1);
}
void reverse(int i)
{
if (i > 5)
return ;
printf(“%d “, i);
return reverse((i++, i));
}
a) 1 2 3 4 5
b) Segmentation fault
c) Compilation error
d) Undefined behaviour

View Answer

Answer:a

3. In expression i = g() + f(), first function called depends on
a) Compiler
b) Associativiy of () operator
c) Precedence of () and + operator
d) Left to write of the expression

View Answer

Answer:a

4. What is the value of i and j in the below code?

#include <stdio.h>
int x = 0;
int main()
{
int i = (f() + g()) || g();
int j = g() || (f() + g());
}
int f()
{
if (x == 0)
return x + 1;
else
return x – 1;
}
int g()
{
return x++;
}
a)i value is 1 and j value is 1
b)i value is 0 and j value is 0
c)i value is 1 and j value is undefined
d)i and j value are undefined

View Answer

Answer:d

5. What is the value of i and j in the below code?

#include <stdio.h>
int x = 0;
int main()
{
int i = (f() + g()) | g(); //bitwise or
int j = g() | (f() + g()); //bitwise or
}
int f()
{
if (x == 0)
return x + 1;
else
return x – 1;
}
int g()
{
return x++;
}
a) i value is 1 and j value is 1
b) i value is 0 and j value is 0
c) i value is 1 and j value is undefined
d) i and j value are undefined

View Answer

Answer:c

6. What is the output of this C code?

#include <stdio.h>
int main()
{
int x = 2, y = 0;
int z = y && (y |= 10);
printf(“%d\n”, z);
return 0;
}
a) 1
b) 0
c) Undefined behaviour due to order of evaluation
d) 2

View Answer

Answer:b

7. What is the output of this C code?

#include <stdio.h>
int main()
{
int x = 2, y = 0;
int z = (y++) ? 2 : y == 1 && x;
printf(“%d\n”, z);
return 0;
}
a) 0
b) 1
c) 2
d)Undefined behaviour

View Answer

Answer:b

8. What is the output of this C code?

#include <stdio.h>
int main()
{
int x = 2, y = 0;
int z;
z = (y++, y);
printf(“%d\n”, z);
return 0;
}
a) 0
b) 1
c) Undefined behaviour
d) Compilation error

View Answer

Answer:b

9. What is the output of this C code?

#include <stdio.h>
int main()
{
int x = 2, y = 0, l;
int z;
z = y = 1, l = x && y;
printf(“%d\n”, l);
return 0;
}
a) 0
b) 1
c) Undefined behaviour due to order of evaluation can be different
d) Compilation error

View Answer

Answer:b

10. What is the output of this C code?

#include <stdio.h>
int main()
{
int y = 2;
int z = y +(y = 10);
printf(“%d\n”, z);
}
a) 12
b) 20
c) 4
d) Either 12 or 20

View Answer

Answer:b

For more Visit the Link:

Computer Science MCQ All Topic C programming MCQ All Topic

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button