What is the difference between block scope and function scope in C? I was told that any variables declared inside curly brackets counts as being in block scope, but when we declare a function, it starts and closed with a curly bracket. I'm confused.
Asked
Active
Viewed 2,817 times
0
-
You are not, hopefully someone will give you a complete answer, I can't know because It's late in my country. – Iharob Al Asimi Feb 18 '15 at 01:56
-
what is the question? – Iłya Bursov Feb 18 '15 at 02:02
-
@Lashane: The question is clear enough. The C standard defines the terms "function scope" and "block scope"; see [N1570](http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf) 6.2.1. – Keith Thompson Feb 18 '15 at 02:15
-
@KeithThompson ok, so question is "Im banned from google, I don't wanna read books, but I like posting questions on SO"? – Iłya Bursov Feb 18 '15 at 02:19
-
http://stackoverflow.com/questions/7933814/difference-between-local-scope-and-function-scope – Iłya Bursov Feb 18 '15 at 02:24
1 Answers
9
In C language function scope is a formal term that describes scope of labels. A label is visible in the entire function, regardless of where in that function it is declared. Labels are the only entities that have that unusual property, hence the need for special kind of scope for them. Nothing else can have function scope.
Variables cannot have function scope. All variables declared locally always have block scope. The outermost pair of { ... }
that envelops the entire function is also a block.

AnT stands with Russia
- 312,472
- 42
- 525
- 765