Skip to main content

STRUCTURE OF A 'C' PROGRAM

 WHAT IS THE STRUCTURE OF 'C' PROGRAM? 

               As we all know 'C' is a high-level programming language used to write executable programs with logics and it is called MOTHER of all other programming languages. Today, we`ll learn how is a program written in C? with proper syntax or structure.



             C programs or any other high-level programming language programs are written with the help of functions. Without any function no program can be written. It is essential that in every C program one function must have a name main. The main function is the very first function of a C program. It is the part of the program, from where the execution starts, which has the definitions of other functions and may access other functions of the program which are pre-defined. It is necessary that any other function definitions must be defined separately, either ahead of or after the main function. 

for example:

#include<stdio.h> 

main( )


ELEMENTS OF 'C' PROGRAMMING.

     Elements are the necessary things that must be in a C program.

1: PREPROCESSOR COMMANDS:

            These commands informs the compiler to perform preprocessing before doing actual compilation of the program. Example #include<stdio.h>  is a preprocessor command which tells a C compiler to include stdio.h file before going to actual compilation which contains function support for input output operations.

2: FUNCTIONS: 

           These are the main building blocks of C program. Every C program will have one or more functions and there is mandatory function which is called main( ) function. Functions must have function heading, which consists of function name, followed by an optional list of arguments, enclosed in parentheses.  



3: VARIABLES:

             These programming elements are used to hold numbers, strings and complex data for computations. I had made a complete separate blog on variables of C programming, so to learn more about variables click on the link.

4: STATEMENTS AND EXPRESSIONS:

            Expressions are used to combine variables and constants to create new values. Statements are expressions, assignments, function calls, or control flow statements which make up C programs. Each compound statement is enclosed within a pair of braces { }.
 

5: COMMENTS:

         These are strings enclosed in symbols as shown below.
/*....String to be written....*/
         These constructs are used to give additional information about other C program constructs. A comment can be written on multiple lines, if needed. 

/*Example Program*/

#include<stdio.h>                    
main ( )
{
printf("C Programming");       
return 0;                                  
}

OUTPUT: C Programming



EXPLANATION ABOUT HOW DOES THIS PROGRAM WORKS:

  • Here, stdio.h is a header file (standard input output header file) and #include is command to use the code from the header file in our source code. When compiler encounters printf( ) function and doesn`t find stdio.h header file, compiler shows error.
  • Every program starts from main( ) function.
  • printf( ) is a library function to display output which only works if #include<stdio.h> is included at the beginning.
  • return 0 is a function return type match to function definition. 

I have written more 2 blog previously on programming, click on the link to have a look on those blogs too.https://brijrajrastog.blogspot.com/

You can follow me on instagram, just click on the below link.







Comments