C& CPP Tutorials
About C
Program Structure
Running C Program
Variables, constants
Operators
Control Structure
Array
Function
Pointers
Preprocessor
Structure
File
Bitwise Operators
Recursion
 Data Structures
Introduction
Stacks
Queues
Linked List
Sorting 
Searching
 Test Your Skill
Fundamentals
Input and Output
Branching and Looping
Function
Pointers I
Pointers II
Structure and Union
Sample Problems I
Sample Problems II
 Help and Support
C Forum
Source code
C  Yahoo Group
C Compilers
 

Basic Structure of C Programs

C program can be viewed as a block of building blocks called functions. A function is a subroutine that may include one or more statement designed to perform a specific task. To write a C program we first create a function and then put them together. A C program may contain one or more section  as below.

    Documentation Section
    Link Section
    Definition Section
   Global Declaration Section
   main() Function Section
    {

       Declaration Part

       Executable Part
    }

   Subprogram section
  
    Function 1


    Function 2

       -

       -

    Function n

 
Documentation section consist of set of comment, purpose of the program, Program logic etc. The link section provide instruction to the compiler to link function from the system library. The definition section define all symbolic constants. 

 There are some variable that  are used in more than one function such variable are called global variable and are declared in the global declaration section that is outside of the  functions.

Every C program must have one main() function section. This section contains two parts declaration part and executable part. The declaration part declare all the variable used in the executable part. There is at lest one statement in the executable part. These two part must appear between the opening and the closing brace. The program execution begin at the opening braces and end in the closing brace. The closing brace of the main function section is the logical end of the program. All statement in the  declaration section and executable parts end with semicolon.

The subprogram section contain all the user-defined function that are called in the main function.User defined functions are generally placed immediately after the main function. Although they may apper any order.

C's Character Set

C does not use, nor requires the use of, every character found on a modern computer keyboard. The only characters required by the C Programming Language are as follows:

  • A - Z

  • a -z

  • 0 - 9

  • space . , : ; ' $ "

  • # % & ! _ {} [] () < > |

  • + - / * =

The use of most of this set of characters will be discussed throughout the course.

C Language Keywords

The following names are reserved by the C language. Their meaning is already defined, and they cannot be re-defined to mean anything else.

 


  auto         break     case        char      continue    default
  do           double    else         enum     extern      float
  for           goto       if             int         long         register
  return      short      sizeof       static    struct        switch
  typedef    union     unsigned   void     volatile      while


Other than these names, you can choose any names of reasonable length for variables, functions etc. The names must begin with a letter or underscore (letters are better), and then can contain letters, numbers and underscores.

Back Next
 

Google