0

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.

Vimzy
  • 1,871
  • 8
  • 30
  • 56

1 Answers1

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