Code: #include int i; void increment( int i ) { i++; } int main() { for( i = 0; i < 10; increment( i ) ) { } printf("i=%d\n", 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 loop indefinitely


Correct Option: D

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) It will not compile. This option is incorrect. The code provided will compile without any errors.

Option B) It will print out: i=9. This option is incorrect. The program will not print "i=9" because the increment function is not modifying the global variable i. It is modifying a local variable i within the function.

Option C) It will print out: i=10. This option is incorrect for the same reason as Option B. The local variable i within the increment function is being modified, not the global variable i.

Option D) It will loop indefinitely. This option is correct. The program will enter an infinite loop because the increment function is called within the for loop condition, but it is not actually modifying the global variable i. Therefore, i will always remain 0, and the condition i &lt; 10 will always be true.

The correct answer is D. It will loop indefinitely because the increment function is not modifying the global variable i.

Find more quizzes: