In C, precedence of unary * and multiplication: evaluate this expression. #include<stdio.h> int main() { int i = 3, j, k; j = &i; printf("%d ", i**ji + *j); return 0; }

Difficulty: Easy

Correct Answer: 30

Explanation:


Introduction / Context:
This expression combines dereferencing and arithmetic. In C, whitespace is irrelevant; ij is parsed as i * *j (multiplication by the dereferenced value). Understanding operator precedence avoids misreading the expression.


Given Data / Assumptions:

  • i = 3
  • j = &i → *j = 3
  • Expression: i * *j * i + j


Concept / Approach:
Multiplication is left-associative, and unary (dereference) applies to j to yield 3. So evaluate products first, then addition.


Step-by-Step Solution:
Compute *j = 3Multiply i * *j → 3 * 3 = 9Multiply by i again → 9 * 3 = 27Add j → 27 + 3 = 30Print 30


Verification / Alternative check:
Introduce temporaries: a = j; printf("%d\n", iai + a); gives the same result.


Why Other Options Are Wrong:
(b) stops before the final addition. (c) and (d) ignore parts of the expression. (e) does not arise from the given arithmetic.


Common Pitfalls:
Misreading as an exponent operator (C has none), or as double-dereference; here the two stars are separate operators.


Final Answer:
30

More Questions from Pointers

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion