C Programming - Expressions
Exercise : Expressions - Yes / No Questions
- Expressions - General Questions
- Expressions - Find Output of Program
- Expressions - True / False Questions
- Expressions - Yes / No Questions
1.
Are the following two statement same?
1. | a <= 20 ? (b = 30): (c = 30); |
2. | (a <=20) ? b : (c = 30); |
Answer: Option
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;
}
2.
Two different operators would always have different Associativity.
Answer: Option
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.
3.
Will the expression *p = p be disallowed by the compiler?
Answer: Option
Explanation:
Because, here even though the value of p is accessed twice it is used to modify two different objects p and *p
4.
Every operator has an Associativity
Answer: Option
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.
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers