Operation ‘a = a * b + a’ can also be written as : (a) a *= b + 1 ; (b) (a * b) != (b + a) ; (c) a = (b + 1) * a ; (d) a *= b + a
(a) and (c) are correct.
Factorise the target expression first.
\(a = a\times b + a = a\,(b+1)\)
So any equivalent statement must multiply a by (b + 1).
Statement (a) — correct. A compound assignment in C expands with the whole right-hand side as one operand:
a *= b + 1; ≡ a = a * (b + 1);
This is the key rule of the question. The right-hand expression is evaluated completely before the multiplication, exactly as if it were parenthesised, so a *= b + 1 is not a = a*b + 1. Expanding, a*(b+1) = a*b + a ✓.
Statement (c) — correct. a = (b + 1) * a; is the same product written the other way round, and multiplication is commutative ✓.
Statement (b) — wrong. != is the inequality operator, not an assignment. The line (a * b) != (b + a); merely computes a truth value, discards it and leaves a completely unchanged ✗.
Statement (d) — wrong. By the same expansion rule, a *= b + a; means a = a * (b + a), which is \(ab+a^{2}\), not \(ab+a\). The two agree only in the special case a = 1 ✗.
Step — assemble. (a) and (c) are equivalent, giving option 4.
Check with numbers. Take a = 3, b = 4. The target is \(3\times4+3=15\). Statement (a): 3 * (4+1) = 15 ✓. Statement (c): (4+1) * 3 = 15 ✓. Statement (d): 3 * (4+3) = 21 ✗. One substitution settles the whole question.
The general rule to carry away. For any compound operator, x op= expr is defined as x = x op (expr) — the implied parentheses around the entire right-hand side are what trip people up with *=, /= and -=. Note also that x op= expr evaluates x only once, which matters when the left side has side effects such as arr[i++] *= 2.
Hence, the equivalent forms are (a) and (c).
The function "isalnum( )" returns a non-zero value if the character is alphanumeric and zero otherwise. What is header file to be used in the main program ?
To read a integer variable, find the correct format given below :
Int m;
Find the correct list, which is the reverse (at all levels) of the given list :
[[4, 7, 8], 2, 9, [19, 6], 20, 3]
(i) 3, 20
(ii) 9, 2
(iii) [6, 19]
(iv) [8, 7, 4]
Which of the following is not an infinite loop ?
(A) int i = 1;
while (1)
{
i++ ;
}
(B) for ( ; ; ) ;
(C) int t = 0, f ;
while (t)
{
f = 1;
}
(D) int y, x = 0 ;
do
{
y = x;
}
while (x == 0);
The three types of loops available in C language are
i. for
ii. while
iii. do-while
Which loops do not operate without testing the condition even once ?
Match the following :
| List – I | List – II |
| a. associativity | i. memory storage |
| b. # define | ii. if-then-else |
| c. auto | iii. operators with equal precedence |
| d. conditional operator | iv. define operator |
Codes :
Assertion (A) : 'C' uses many data types such as integers (short and long) and float etc.
Reason (R) : Conversion specifier used for short unsigned integer is % lu.
Which bitwise operator is suitable for turning off a particular bit in a number ?
Which storage class is used for the variables that are often required in a program ?
Which is not a proper way of array declaration ?
Which of the following is NOT a state function or state variable in a thermodynamic system?