Search This Blog


Thursday, September 12, 2019

Structure of C programs

          PREPROCESSOR DIRECTIVE SECTION
        ↓
          GLOBAL SECTION
        ↓
          MAIN SECTION
        ↓
          USER DEFINED SECTION

EXAMPLE:-

structure of c,structure of c program
C program structure

⇒ #include :-  

  • It is a preprocessor directive which is used to include header file in a program .
  • All preprocessor directive must be started with "#" symbol.
  • There is  no space between # and include.

     syntax:-

            #include<header file>

 ⇒HEADER FILE:-

  • It is a special file that consist of all predefined function.
  • The file extension of header file is ".h".
  • It is mainly used to access function in a program.    

  There are some header file in C:-


  • stdio.h    
  • conio.h
  • math.h
  • string.h
  • ctype.h
  • alloc.h
  • malloc.h
  • dos.h
  • graphics.h
  • process.h
  • stdlib.h
  • etc.

⇒ MAIN( ) FUNCTION :-


  • It is an entry point in which we write source code according to requirement ,so it is called user defined function.
  • The elements of program must be started with main function.

 In C


      syntax:-

                     main( )
                     {                                        //starts execution
                       block of statements;
                      }                                       //ends execution

In C++

        syntax 1:-

                      void main( )
                      {
                        block of statements;
                        }
  "NOTE: void is the keyword that specifies main( ) function does not return any value."

        syntax 2:-

                      int main( )
                         {
                           block of statements;
                          }
  "NOTE: here main( ) function can return any integer type value."                    

⇒ clrscr( ):-

  • This function is used to clear the previous output on the console.
  • This funcion is available in "conio.h" header file.

    syntax:-


                  clrscr( );
             

⇒ getch( ):-

  • It is mainly used to input one character at a time, so it holds the output screen for viewing output.
  • It is available in "conio.h" headeer file.   

   syntax:-  

            getch( );



No comments:

Post a Comment