Multiple choice

#include <stdio.h> int i; void increment( int i ) { i++; } int main() { for( i = 0; i < 10; increment( i ) ) { } printf(i=%dn, i); return 0; }
What will happen when the program above is compiled and executed?

  1. It will not compile.

  2. It will print out: i=9.

  3. It will print out: i=10.

  4. It will print out: i=11.

  5. It will loop indefinitely

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

The global variable 'i' is used in the for-loop condition and print statement. However, the increment function takes 'int i' as a parameter, which shadows the global variable. The function increments its local parameter, not the global 'i'. Therefore, the global 'i' remains 0 forever, and the loop condition i < 10 is always true, causing an infinite loop.