Yes / No Questions

Question 1 :

Are the following two statement same?
1. a <= 20 ? (b = 30): (c = 30);
2. (a <=20) ? b : (c = 30);


A). Yes
B). No
Answer : Option B

Explanation :

No, the expressions 1 and 2 are not same.

1. a <= 20 ? (b = 30) : (c = 30); This statement can be rewritten as,

if(a <= 20)
{
    b = 30;
}
else
{
    c = 30;
}

2. (a <=20) ? b : (c = 30); This statement can be rewritten as,
if(a <= 20)
{
    //Nothing here
}
else
{
    c = 30;
}


Question 2 :

Two different operators would always have different Associativity.


A). Yes
B). No
Answer : Option B

Explanation :

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 3 :

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


A). Yes
B). No
Answer : Option B

Explanation :

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


Question 4 :

Every operator has an Associativity


A). Yes
B). No
Answer : Option A

Explanation :

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.