Friday 3 February 2012

Basic Structure of C Program

Dear Visitors,
           In this post you learn about the Basic Structure of C Program.....


SO FRIENDS LETS START OUT LESSON

  • Basic Structure of C Program:-
"The format or way according to which a computer program is written is called the structure of the program". The program structure of different programming languages is different. C is a structured programming language. It provides a well defined way of writing programs.
The basic structure of C program consists of the following main parts.

1). Preprocessor Directives
2). The main() Function
3). C Statement
                       
              To explain the structure of C program, a program example that prints a message "My first program in C." is given below.

              #include<stdio.h>
              main()
 {     
              printf("My first program in C");
 }


      In the above program:
1). The header file "stdio.h" is used at the beginning of program. This file contains the declarations (or information) of standard input and output functions used to get input and to print output. This header file is included because "printf()" function is used in the main body of program to print message "My first program in C".
                             The lines beginning with # sign indicates that this is an instruction for a C compiler are called Preprocessor directives. The #include<stdio.h> is an example of Preprocessor directive.
2). The "main()" function comes after the preprocessor directives. It indicates the beginning of the actual C program. It is the point at which execution of program is started. 
3). The set of statements (or instructions) of C program are written under the "main()" function between curly brackets i.e { }. Each statement of C program ends with semicolon ( ; ).

1 comment: