95.8k views
2 votes
The scope of a variable declared within a for() loop is:

a) Only known within the for() loop

b) Global across all functions in the file containing the code

c) Local to the function containing the for() loop

d) It depends on the variable type

User Newshorts
by
5.0k points

1 Answer

2 votes

Answer:

a

Step-by-step explanation:

The scope of a variable declared within the for() loop is only known within the for loop.

The variable declared within the for () loop is accessible inside the loop itself and it goes out of scope once it comes out of the loop.

for(int i=1; i<=10;i++) // variable i is declared inside the loop

{

// variable i is accessible inside this block only

}

// variable i goes out of scope

User Kishan Sharma
by
5.2k points