Operators And Expressions(Computer Science > C Program ) Questions and Answers

Question 1. Which of the following operator takes only integer operands?
  1.    +
  2.    *
  3.    /
  4.    %
  5.    None of these
Explanation:-
Answer: Option D. -> %

Question 2. In an expression involving || operator, evaluation
I.   Will be stopped if one of its components evaluates to false
II.  Will be stopped if one of its components evaluates to true
III. Takes place from right to left
IV.  Takes place from left to right
  1.    I and II
  2.    I and III
  3.    II and III
  4.    II and IV
  5.    III and IV
Explanation:-
Answer: Option D. -> II and IV

Question 3. Determine output:
void main()
{
int i=0, j=1, k=2, m;
m = i++ || j++ || k++;
printf("%d %d %d %d", m, i, j, k);
}
  1.    1 1 2 3
  2.    1 1 2 2
  3.    0 1 2 2
  4.    0 1 2 3
  5.    None of these
Explanation:-
Answer: Option B. -> 1 1 2 2

Question 4. Determine output:
void main()
{
int c = - -2;
printf("c=%d", c);
}
  1.    1
  2.    -2
  3.    2
  4.    Error
Explanation:-
Answer: Option C. -> 2

Question 5. Determine output:
void main()
{
int i=10;
i = !i>14;
printf("i=%d", i);
}
  1.    10
  2.    14
  3.    0
  4.    1
  5.    None of these
Explanation:-
Answer: Option C. -> 0

Question 6. In C programming language, which of the following type of operators have the highest precedence
  1.    Relational operators
  2.    Equality operators
  3.    Logical operators
  4.    Arithmetic operators
Explanation:-
Answer: Option D. -> Arithmetic operators

Question 7. What will be the output of the following program?
void main()
{
int a, b, c, d;
a = 3;
b = 5;
c = a, b;
d = (a, b);
printf("c=%d d=%d", c, d);
}
  1.    c=3 d=3
  2.    c=3 d=5
  3.    c=5 d=3
  4.    c=5 d=5
Explanation:-
Answer: Option B. -> c=3 d=5

Question 8. Which of the following comments about the ++ operator are correct?
  1.    It is a unary operator
  2.    The operand can come before or after the operator
  3.    It cannot be applied to an expression
  4.    It associates from the right
  5.    All of the above
Explanation:-
Answer: Option E. -> All of the above

Question 9. What will be the output of this program on an implementation where int occupies 2 bytes?
#include
void main()
{
int i = 3;
int j;
j = sizeof(++i + ++i);
printf("i=%d j=%d", i, j);
}
  1.    i=4 j=2
  2.    i=3 j=2
  3.    i=5 j=2
  4.    the behavior is undefined
Explanation:-
Answer: Option B. -> i=3 j=2

Question 10. Which operator has the lowest priority?
  1.    ++
  2.    %
  3.    +
  4.    ||
  5.    &&
Explanation:-
Answer: Option D. -> ||