Sail E0 Webinar

MCQs

Total Questions : 35 | Page 1 of 4 pages
Question 1.

Every operator has an Associativity


  1.    Yes
  2.    No
 Discuss Question
Answer: Option A. -> Yes

Yes, Each and every operator has an associativity.

The associativity (or fixity) of an operator is a property that determines how 

operators of the same precedence are grouped in the absence of parentheses. 

Operators may be left-associative, right-associative or non-associative.


Question 2.

Will the expression *p = p be disallowed by the compiler?


  1.    Yes
  2.    No
 Discuss Question
Answer: Option B. -> No

Because, here even though the value of p is accessed twice it is used to modify two 

different objects p and *p


Question 3.

Two different operators would always have different Associativity.


  1.    Yes
  2.    No
 Discuss Question
Answer: Option B. -> No

No, Two different operators may have same associativity.

Example
Arithmetic operators like ++, -- having Right-to-Left associativity.
Relational operators like >, >= also have Left-to-Right associativity.


Question 4.

Are the following two statement same?

1.a <= 20 ? (b = 30): (c = 30);

2.(a <=20) ? b : (c = 30);


  1.    Yes
  2.    No
 Discuss Question
Answer: Option B. -> No


No, the expressions 1 and 2 are not same.
1. a

Question 5.

Associativity of an operator is either Left to Right or Right to Left.


  1.    True
  2.    False
 Discuss Question
Answer: Option A. -> True

Yes, the associativity of an operator is either Left to Right or Right to Left.


Question 6.

In the expression a=b=5 the order of Assignment is NOT decided by Associativity of operators


  1.    True
  2.    False
 Discuss Question
Answer: Option B. -> False

The equal to = operator has Right-to-Left Associativity. So it assigns b=5 then a=b.


Question 7.

Associativity has no role to play unless the precedence of operator is same.


  1.    True
  2.    False
 Discuss Question
Answer: Option A. -> True

Associativity is only needed when the operators in an expression have the same 

precedence. Usually + and - have the same precedence.

Consider the expression 7 - 4 + 2. The result could be either (7 - 4) + 2 = 5 or 7 

- (4 + 2) = 1. The former result corresponds to the case when + and - are left-

associative, the latter to when + and - are right-associative.

Usually the addition, subtraction, multiplication, and division operators are left-associative, 

while the exponentiation, assignment and conditional operators are right-associative. To 

prevent cases where operands would be associated with two operators, or no operator at 

all, operators with the same precedence must have the same associativity.


Question 8.



What will be the output of the program?
#include<stdio.h>
int main()
{
int i=2;
int j = i + (1, 2, 3, 4, 5);
printf("%d\n", j);
return 0;
}
  1.    4
  2.    7
  3.    6
  4.    5
 Discuss Question
Answer: Option B. -> 7

Because, comma operator used in the expression i (1, 2, 3, 4, 5). The comma 

operator has left-right associativity. The left operand is always evaluated first, 

and the result of evaluation is discarded before the right operand is evaluated. 

In this expression 5 is the right most operand, hence after evaluating expression 

(1, 2, 3, 4, 5) the result is 5, which on adding to i results into 7.


Question 9.

The expression of the right hand side of || operators doesn't get evaluated if the 

left hand side determines the outcome.


  1.    True
  2.    False
 Discuss Question
Answer: Option A. -> True

Because, if a is non-zero then b will not be evaluated in the expression (a || b)


Question 10.


What will be the output of the program?


#include<stdio.h>
int main()
{
char ch;
ch = 'A';
printf("The letter is");
printf("%c", ch >= 'A' && ch = 'A' && ch
  1.    The letter is a Now the letter is A
  2.    The letter is A Now the letter is a
  3.    Error
  4.    None of above
 Discuss Question
Answer: Option A. -> The letter is a Now the letter is A

Step 1: char ch; ch = 'A'; here variable ch is declared as an character 

type an initialized to 'A'.

Step 2: printf("The letter is"); It prints "The letter is".

Step 3: printf("%c", ch >= 'A' && ch <= 'Z' ? ch + 'a' - 'A':ch);

The ASCII value of 'A' is 65 and 'a' is 97.

Here

=> ('A' >= 'A' && 'A' <= 'Z') ? (A + 'a' - 'A'):('A')

=> (TRUE && TRUE) ? (65 + 97 - 65) : ('A')

=> (TRUE) ? (97): ('A')

In printf the format specifier is '%c'. Hence prints 97 as 'a'.

Step 4: printf("Now the letter is"); It prints "Now the letter is".

Step 5: printf("%cn", ch >= 'A' && ch <= 'Z' ? ch : ch + 'a' - 'A');

Here => ('A' >= 'A' && 'A' <= 'Z') ? ('A') : (A + 'a' - 'A')

=> (TRUE && TRUE) ? ('A') :(65 + 97 - 65)

=> (TRUE) ? ('A') : (97)

It prints 'A'

Hence the output is

The letter is a
Now the letter is A



Latest Videos

Latest Test Papers