

InterviewSolution
Saved Bookmarks
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
1. |
Associativity has no role to play unless the precedence of operator is same. |
Answer» 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. | |
2. |
The expression of the right hand side of operators doesn't get evaluated if the left hand side determines the outcome. |
Answer» Because, if a is non-zero then b will not be evaluated in the expression (a || b) | |
3. |
In the expression the order of Assignment is NOT decided by Associativity of operators |
Answer» The equal to = operator has Right-to-Left Associativity. So it assigns b=5 then a=b. | |
4. |
Associativity of an operator is either Left to Right or Right to Left. |
Answer» Yes, the associativity of an operator is either Left to Right or Right to Left. | |
5. |
Assuming, integer is 2 byte, What will be the output of the program? |
Answer» The integer value 2 is represented as 00000000 00000010 in binary system. Negative numbers are represented in 2's complement method. 1's complement of 00000000 00000010 is 11111111 11111101 (Change all 0s to 1 and 1s to 0). 2's complement of 00000000 00000010 is 11111111 11111110 (Add 1 to 1's complement to obtain the 2's complement value). Therefore, in binary we represent -2 as: 11111111 11111110. After left shifting it by 2 bits we obtain: 11111111 11111000, and it is equal to "fff8" in hexadecimal system. | |
6. |
Two different operators would always have different Associativity. |
Answer» 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. | |
7. |
Will the expression be disallowed by the compiler? |
Answer» Because, here even though the value of p is accessed twice it is used to modify two different objects p and *p | |
8. |
Every operator has an Associativity |
Answer» 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. | |