ExamVeda
Login
Home
31
Which of the following operator takes only integer operands?
Discuss
Answer & Solution
Answer: Option D
Solution:
In C, the modulus operator (%) takes only integer operands. It is used to find the remainder when one integer is divided by another. This operator is specifically designed for integer arithmetic.

Option A (+) represents the addition operator, which can take both integer and floating-point operands.
Option B (*) represents the multiplication operator, which can take both integer and floating-point operands.
Option C (/) represents the division operator, which can take both integer and floating-point operands.
Option E (None of these) is incorrect because % is the operator that specifically takes only integer operands; the other options can take both integer and floating-point operands.
32
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
Discuss
Answer & Solution
Answer: Option D
Solution:
In C, the logical OR operator (||) behaves as follows:

If the first operand evaluates to true, the entire expression is considered true, and further evaluation is stopped.
If the first operand evaluates to false, the evaluation continues with the second operand. If the second operand evaluates to true, the entire expression is considered true.
If both operands evaluate to false, the entire expression is considered false.

Based on this behavior, the evaluation doesn't stop when one of its components evaluates to true (contrary to option II). Instead, it stops when one of its components evaluates to false.

Regarding option IV, the evaluation of the logical OR operator (||) is left-to-right, so option IV is correct.

So, the correct answer is indeed Option D: II and IV, which means the evaluation will stop when one of its components evaluates to false, and the evaluation takes place from left to right. Thank you for pointing out the correction.
33
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);
}
Discuss
Answer & Solution
Answer: Option B
Solution:
In this C program, the expression i++ || j++ || k++ involves the logical OR (||) operator. Here's how it works:

- It evaluates from left to right.
- It stops evaluating as soon as it finds a true condition because in a logical OR operation, if one operand is true, the result is true.

Let's break it down step by step:
- i is initially 0. i++ returns 0 (post-increment), but it increments i to 1.
- j is initially 1. j++ returns 1 (post-increment), and it increments j to 2.
- k is initially 2. k++ returns 2 (post-increment), and it increments k to 3.

Now, the expression is evaluated:
- 0 || 1 is true because one of the operands is true.
- Since the result is true, the evaluation stops.

After the evaluation:
- m is assigned the value 1 because the result is true.
- i is 1 because i was incremented during the evaluation.
- j is 2 because j was incremented during the evaluation.
- k is 2 because k was not incremented further.

Therefore, the output of the printf statement is 1 1 2 2, which corresponds to Option B.
34
Determine output:
void main()
{
      int c = - -2; 
      printf("c=%d", c); 
}
Discuss
Answer & Solution
Answer: Option C
Solution:
In this C program, the expression - -2 involves the use of the unary minus operator (-) applied twice to the number 2.

- The first - operator negates the number 2, resulting in -2.
- The second - operator negates -2, which effectively makes it positive again, resulting in 2.

So, the variable c is assigned the value 2, and the output of the printf statement is c=2, which corresponds to Option C.
35
Determine output:
void main()
{ 
      int i=10; 
      i = !i>14; 
      printf("i=%d", i); 
}
Discuss
Answer & Solution
Answer: Option C
Solution:

In the expression !i>14 , NOT (!) operator has more precedence than ' >' symbol. ! is a unary logical operator. !i (!10) is 0 (not of true is false). 0>14 is false (zero).

36
In C programming language, which of the following type of operators have the highest precedence
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
37
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);
}
Discuss
Answer & Solution
Answer: Option B
Solution:

The comma operator evaluates both of its operands and produces the value of the second. It also has lower precedence than assignment. Hence c = a, b is equivalent to c = a, while d = (a, b) is equivalent to d = b.

38
Which of the following comments about the ++ operator are correct?
Discuss
Answer & Solution
Answer: Option E
No explanation is given for this question. Let's Discuss on Board
39
What will be the output of this program on an implementation where "int" occupies 2 bytes?
#include <stdio.h>
void main()
{
      int i = 3;
      int j;
      j = sizeof(++i + ++i);
      printf("i=%d j=%d", i, j);
}
Discuss
Answer & Solution
Answer: Option B
Solution:

Evaluating ++i + ++i would produce undefined behavior, but the operand of sizeof is not evaluated, so i remains 3 throughout the program. The type of the expression (int) is reduced at compile time, and the size of this type (2) is assigned to j.

40
Which operator has the lowest priority?
Discuss
Answer & Solution
Answer: Option D
Solution: