The Format of writing a Program in c++ is called its
Structure. The Basic structure of C++ is very flexible. It increases the power
of language. Structure of c++ consists of following parts.
BAsic structure of cpp |
· Main() function
· Program body (c++ statement)
Preprocessor Directive
Preprocessor Directive is an instruction given to the
compiler before the execution of actual program. Preprocessor directives are
also known as Compiler Directive. The preprocessor directive is processed by a
program known as preprocessor. It is part of c++ compiler.IT modifies C++
source program before Compilation. The semicolon is not used at the end of
preprocessor directives.
Include Preprocessor
Include preprocessor directive is used to include header
files in the program. The syntax of using this directive is as follows:
#include<iostream.h>
The above statement tells the compiler to include the file
iostream.h in source program before compiling it.
Header file
Header Files are the collection of a standard library
function to perform different tasks. There are many header files for different
purpose. Each files contain different types of predefined functions. Many
header files can be included in one program. The header file must be included
in the program before calling any of its function in the program.
The extinction of a header file is .h. The include
preprocessor directive is used to include header files in programs. These files
are provided by c++ compiler system.
The header file are normally stored in INCLUDE subdirectory.
The name of header file is written in angle brackets.
Syntax
The syntax of using
header file is as follows:
#include<header_file_name>
The header file name also be include in Double quotes as
follows”
#include”header file name”
Example
#include<iostream>
Iostream stand for input output steam. This header file
contains the definitions of built in input and output function and object.
A header file math.h is used in program to use predefined
mathematical functions. The following statement is used to include this file in
program.
#include”math.h”
Main ( ) Function
The main function is the starting point of c++ program. When
the program is run the control enters main() function and starts executing its
statements.
Each program must contain main () function. If a program
does not contain main functions, it can be compiled but can not be executed.
Any number of statement can be written in the body of main () function. The
syntax of main function is as follows.
Void main ()
{
Body of main function
}
C++ statement/ Program Body
The statement of the program written in curly braces. The
curly brace { is called opening brace and }is closing brace. The braces are
also known as delimiters. These statements are collectively known as the body
of a program. Each statement in C++ language is terminated by semicolon.
A statement in C++ language is an instruction for the
computer to perform a task. Computer perfroms these instructions one by one in
the same sequence in which these instruction are written.
Example:
The following example explains the basic structure of C++
program.
Main function : void main()
{
[Programe body] Cout <<”welcome to
rbatec”;
}
·
The first line in the preprocessor directive to
include a header file Iostream.h.
·
The second line is main function where the
execution of program starts.
Using ‘Cout’
The cout object is used to print a message on the screen.
The message may consist of strings and value. A string is a set of characters.
The cout object is used with the insetion operator <<. Anything written
after insertion operator in displayed on the screen.
cout body |
Post a Comment