2.1 Blocks

A block in C is a section of code surrounded by braces { }. Understanding the definition of a block is very important to understanding many other C concepts, such as scope, visibility, and external or internal declarations.

The following example shows two blocks, one defined inside the other:

main ()
{              /*  This brace marks the beginning of the outer block  */
   int x;
   if (x!=0)
   {           /*  This brace marks the beginning of the inner block */
      x = x++;
      return x;
   };          /*  This brace marks the end of the inner block        */
}              /*  This brace marks the end of the outer block        */

A block is also a form of a compound statement; a set of related C statements enclosed in braces. Declarations of objects used in the program can appear within a block and affect the object's scope and visibility. Section 2.3 discusses scope; Section 2.4 discusses visibility.


Previous Page | Next Page | Table of Contents | Index