0

What is the scope of a variable declared inside a loop in C ?

7th Oct 2019, 4:49 AM
Himanshu Kumar
Himanshu Kumar - avatar
4 odpowiedzi
+ 1
Only inside the loop
7th Oct 2019, 4:58 AM
Trigger
Trigger - avatar
+ 1
Thomas Williams what if it's a static variable ?
7th Oct 2019, 5:03 AM
Himanshu Kumar
Himanshu Kumar - avatar
+ 1
Scope of variable can be global or local. In C you can declare variables global and use it in every function of your program or you can declare variables external to your .c file and variable can be in other .c or .h in such case you need to use extern keyword. So now static , static variables can persist value and there scope can be limited to a .c file or a function in which they are declared. I think static variables very useful.
8th Oct 2019, 7:16 AM
Ankur
Ankur - avatar
0
Himanshu Kumar Depends on context. I'm not sure you can declare a static variable in a loop
7th Oct 2019, 6:03 AM
Trigger
Trigger - avatar