LearnFrenzy
Sign in Take a free test

C Loops · Loops MCQ · Question 6

Scope of a variable declared in a for loop header Answer, explanation & discussion

  • MCQ
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 6 Back to Exercise

After for (int i = 0; i < 5; i++) { … }, can you use i on the next line?

  • A Yes, it holds 5
  • B Yes, it holds 4
  • C No – since C99 its scope is the loop only Correct
  • D Only if it is static
Correct Answer: Option C

A variable declared in the for initialisation exists only for the loop. Declare it before the loop if you need its final value.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links