Monday, August 31, 2009

What is the basic structure of a C program, Hello program in c language.

Basic structure of C program, Hello program in C : The format of writing C program is called its structure. The basic structure of a C program is very flexible. It increases the power of the language.
It consists of following parts:

  • Preprocessor directive
  • Main() function
  • Program body (C Statements)
Hello Program (Example)

Preprocessor directive ------> #include
Main function ------> void main()

Program body ------> {
(C statements) printf("Hello World."); <--- Statement terminator
}

In the above c program,

First line is preorocessor directive to include a header file stdio.h. The preprocessor directives are the commands that give instructions to c preprocessor. Preprocessor is a program that modifies c source program before compilation. Ther preprocessor directives start with hash symbol #.
The second line is main function. The main() function is the place where execution of a C program starts. When the program is executed, The control enters main () function and start executing its statements.
The statements of the program are written in curly braces. The curly brace { is called opening brace and } is called closing brace. The breacs are also known as delimitoers . These statements are collectively known as the body of a pogram.
Every statement in c program is terminated whte a semi colon ( ; ). The compiler generates an error if any statment is not terminated by semi colon.

learn unix c c++

No comments:

Post a Comment

Ads