Basic Structure of a C Program

Sudhakar Atchala
Sudhakar Atchala
17.1 هزار بار بازدید - 5 سال پیش - #clanguage
#clanguage #cprogramming
Basic Structure of a  C Program:-

• A C program is divided into six sections: Documentation,  Header File, Definition, Global Declaration, Main( ) Function, and User Defined Functions.
• While the main section is compulsory, the rest are optional in the structure of the C program.

Comment Section or Documentation Section
Header File Section or Preprocessor Directive Section or Linking Section
Definition Section
Global Variable Declaration Section
main( )
{
     Declaration Part
     Execution Part
}
User_Defined_Function( )
{
      Function body
}

1.Comment Section or Documentation Section
• Comments are useful for understanding the program.
• It Consists of the description of the program such as programmer's name, and creation date.
• Comments can be placed anywhere in the program.
• In a C program, single-line comments can be written using two forward slashes i.e., //, and we can create multi-line comments using /* */.
• i.e., Multi line Comment begins with /*  and ends with */  (Forward Slash and Asterisk symbol.
• // add.c
• Ex: sum=a+b  
• /*add a and b
and store the
result in sum */
• Comments are not compiled and not executed.


2. Header File Section or Preprocessor Directive Section or Linking Section:-
• Any header file is a collection of library functions.
• Ex:- #include stdio.h , #include string.h , #include conio.h
• Library functions are already defined in the compiler.
• printf( ) , scanf( ) functions are available in stdio header file.
• Extension for header file is .h.
• The statements which are executed before compilation are known as pre-processor directives.
• A copy of these header files is inserted into your code before compilation.
• Linker links object code of several library functions to the main program.
3. Definition Section:-
• It is used to define Symbolic Constants or Macros.
• Ex:  #define PI 3.14
• Once we declare a Symbolic Constant then it is not possible to change its value.
• If we try to change macro value, then compiler gives error message.

 4. Global Variable Declaration Section:-
• Global Variables are used anywhere in the program
• If we declare a variable above  main( ) , then it is called as Global Variable.
5.main function( ):-
• Any C Program is a collection of functions.
• Any C Program must contain one function i.e., main function.
• The execution of C Program must always start from main( ).
• main( ) mainly contains 2 parts.
• 1. Declaration Part   2. Execution Part
                   main( )
                   {
                                 Declaration Part
                                 Execution Part
      }
• During declaration part, we can declare variables.
• Execution part is used for calculations, displaying results.
6.User Defined functions or sub program :-
• The functions which are defined by the user.
• Any function contains a block of statements which performs given task.

#BasicStructureofaCProgram #StructureofCProgram #CProgramStructure

explain the basic structure of c program with an example pdf,

basic structure of c program pdf,

basic structure of c program wikipedia,

structure of c program with example pdf,

basic structure of c program ppt,

structure program for student details in c,

general structure of c program,

basic structure of c++ program
5 سال پیش در تاریخ 1397/11/17 منتشر شده است.
17,122 بـار بازدید شده
... بیشتر