C Programming Questions and Answers on Precedence and Order of Evaluation – 1 for Freshers



1. Which of the following operators has an associativity from Right to Left?

a) <=
b) <<
c) ==
d) +=
Answer: d
2. Which operators of the following have same precedence?

P. "!=", Q. "+=", R. "<<="
a) P and Q
b) Q and R
c) P and R
d) P, Q and R
Answer: b
3. Comment on the following statement?

 n = 1;
   printf("%d, %dn", 3*n, n++);
a) Output will be 3, 2
b) Output will be 3, 1
c) Output will be 6, 1
d) Output is compiler dependent
Answer: d
4. Which of the following option is the correct representation of the following code?

e = a * b + c / d * f;
a) e = (a * (b +(c /(d * f))));
b) e = ((a * b) + (c / (d * f)));
c) e = ((a * b) + ((c / d)* f));
d) Both e = ((a * b) + (c / (d * f))); and e = ((a * b) + ((c / d)* f));
Answer: d

Explanation: Verified by e = 1 * 2 + 3 / 4 * 5; and then using respective braces according to the option.
5. What care must be taken during swapping 2 numbers?

   b = (b / a);
    a = a * b;
    b = a / b;
a) Data type should be either of short, int and long
b) Data type should be either of float and double
c) All data types are accepted except for (char *)
d) This code doesn’t swap 2 numbers
Answer: b
6. What should be the output of the following program:

  1.     #include
  2.     int main()
  3.     {
  4.         int a = 1, b = 2, c = 3, d = 4, e;
  5.         e = c + d = b * a;
  6.         printf("%d, %d\n", e, d);
  7.     }
a) 7, 4
b) 7, 2
c) 5, 2
d) Syntax error
Answer: d
7. Which of the following is the correct order of evaluation for the given expression?

a = w % x / y * z;
a) % / * =
b) / * % =
c) = % * /
d) * % / =
Answer: a
8. Which function in the following expression will be called first?

a = func3(6) - func2(4, 5) / func1(1, 2, 3);
a) func1();
b) func2();
c) func3();
d) Cannot be predicted
Answer: d
9. Which of the following operator has the highest precedence in the following?

a) ()
b) sizeof
c) *
d) +
Answer: a
10. Which of the following is a ternary operator?

a) &&
b) >>=
c) ?:
Answer: c
11. Which of the following are unary operators?

a) sizeof
b) –
c) ++
d) all of the mentioned
Answer: d
12. Where in C the order of precedence of operators do not exist?

a) Within conditional statements, if, else
b) Within while, do-while
c) Within macro definition
d) None of the mentioned
Answer: d
13. Associativity of an operator are:

a) Right to Left
b) Left to Right
c) Random fashion
d) Both Right to Left and Left to Right
Answer: d
14. Which of the following method are accepted for assignment?

a) 5 = a = b = c = d;
b) a = b = c = d = 5;
c) a = b = 5 = c = d;
d) None of the mentioned
Answer: b
15. Which of the following is NOT possible with any 2 operators in C?

a) Different precedence, same associativity
b) Different precedence, different associativity
c) Same precedence, different associativity.
d) All of the mentioned
Answer: c
16. Which of the following is possible with any 2 operators in C?

a) Same associativity, different precedence
b) Same associativity, same precedence
c) Different associativity, different precedence
d) All of the mentioned
Answer: d
17. Which of the following operators has the lowest precedence?

a) !=
b) &&
c) ?:
d) ,
Answer: d
18. Comment on the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int x = 3, i = 0;
  5.         do {
  6.             x = x++;
  7.             i++;
  8.         } while (i != 3);
  9.         printf("%d\n", x);
  10.     }
a) Undefined behaviour
b) Output will be 3
c) Output will be 6
d) Output will be 5
Answer: c
19. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int a = -1, b = 4, c = 1, d;
  5.         d = ++a && ++b || ++c;
  6.         printf("%d, %d, %d, %d\n", a, b, c, d);
  7.         return 0;
  8.     }
a) 0, 4, 2, 1
b) 0, 5, 2, 1
c) -1, 4, 1, 1
d) 0, 5, 1, 0
Answer: a
20. What is the output of this C code?

  1.     #include 
  2.     int main()
  3.     {
  4.         int p = 10, q = 20, r;
  5.         if (r = p = 5 || q > 20)
  6.             printf("%d", r);
  7.         else
  8.             printf("No Output\n");
  9.     }
a) 1
b) 10
c) 20
d) No Output
Answer: a

Related

Multiple Choice Questions 8596545231953432429

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item