liveBook · Manning

Block

As explained in Modern C, Third Edition

A block is a grammatical structure that groups declarations and statements within a delimited program region.

A block is a grammatical structure that groups declarations and statements inside a delimited program region. In C, braces usually mark a compound statement and its scope boundary. Blocks can nest: a function body contains a for construct, which contains its loop body. section 2.2

Nested blocks in a function

int main(int argc, char* argv[]) { for (...) { /* loop body */ } } The body of main is one block. The for construct forms a primary block, and its body forms a secondary block. Parameters such as argc and argv have visibility throughout the function body. section 2.2

TAKEAWAY

  • A declaration has block scope when its visibility extends from the declaration to the end of its enclosing block. section 2.2
  • The function body, for construct, and loop body create three nested blocks beneath file scope in the example. section 2.2
  • File scope lies outside parentheses and braces; identifiers there are commonly called globals. section 2.2

How Modern C, Third Edition covers it

How deep it goes
Defines block grammar, distinguishes primary and secondary blocks, and traces four nested scope levels without descending into implementation mechanics.
Examples
Uses main, its parameter list and body, and a for loop with a nested loop body.
What you can do after
Evaluate/understand identifier visibility by locating declaration points and enclosing blocks.
How it connects
Connects blocks to scope, declarations, function parameters, for constructs, compound statements, and file scope.

Also explained in

Compare how 5 books explain block →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C, Third Edition. The section links point to the parts of the book it draws on.