1.1 Basic Structure of C Program in C Language


 

C Language Tutorials 

 Basic Structure of C Program 





The format of writing C program
The basic structure of a C program is very flexible
It consists of following parts:
  • Preprocessor directive
  • main() function
  • Program body (C statements)
Example:

#include <stdio.h>

void main()

{

 printf("Hello World .");

}




Preprocessor Directive

  • First line in a processor directive to include the header file stdio.h
  • It gives instructions to C preprocessor
  • Preprocessor is a program that modifies C source program before compilation
  • Preprocessor directives starts with hash # symbol

main() Function

  • main () function is the place where execution of C program starts
  • When a program executes, the control enters main () function and  starts executing its Statements

 

Program Body

  • Statements are written in curly braces
  • The braces are also known as delimiters
  • These statements are collectively known as the body of program
  • Every statement program is terminated with a semi colon;


Define Preprocessor

  • It is used to define a constant
  • It starts with # symbol
  • It is not terminated with semicolon ;

 Syntax

# define identifier value

# It indicates the start of preprocessor directive

Example

 # define PI 3.141593

 

Header Files

  • It is collection of standard library functions to perform different tasks
  • Standard library functions or simply C Library functions are built-in functions in C programming
  • Each header file contains different types of predefined functions
  • Many header files can be included in one program
  • Header file must be included before calling of its function in the program
  • Extension of header file is .h
  • The include preprocessor directive is used to include header files in program
  • These files are provided by C compiler system
  • Header files are normally stored in INCLUDE subdirectory

Syntax:

# include<Header file name> or # include “header_file_name”

 

Example

# include<stdio.h>

#include<math.h>

#include<conio.h>

 

 

main() function

  • main() function is the place where the execution starts
  • When the program is executed, the control enters main() function and starts its execution
  • Each program contains main() function
  • If a program does not contains main function, it can be compiled but not executed
  • Statements are written in the body of main function
  • Body is enclosed in curly braces { }

Syntax

void main ()

{

Body of main function

}

 

  • The definition of main function starts with keyword void
  • void means that the function will return no value





Post a Comment

0 Comments

Close Menu