Saturday, October 10, 2020

Structure of a 'C' Program

C program is a collection of one or more functions. Every function is a collection of statements that perform a specific task.

The general structure of C program is:

Structure of a 'C' Program

Comments can be placed anywhere in a program and are enclosed between the delimiters /* at */. Comments are generally used for documentation purposes. Preprocessor directives are processed through preprocessor before the C source code passes through compiler. The commonly used preprocessor directives are #include and #define. #include is used for including header files. #define is used to define symbolic constants and macros.

Every C program has one or more functions. If a program has only one function then it must be main(). Execution of every C program starts with main() function. It has two parts, declaration of local variables and statements. The scope of the local variable is local to that function only. Statements in the main() function are executed one by one. Other functions are the user-defined functions, which also have local variables and C statements. They can be defined before or after main(). It may be possible that some variables have to be used in many functions, so it is necessary to declare them globally. These variables are called global variables.


No comments:

Post a Comment