Multiple choice

What will be the output of the following function?

main() { int a[10]; printf(%d,*a+1-*a+3); }

  1. Garbage value

  2. 4

  3. Error

  4. None of these

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The expression *a + 1 - *a + 3 simplifies mathematically because the terms *a and -*a cancel each other out. This leaves 1 + 3, which results in 4, regardless of the values stored in the array.