Structure of C++ Program

Advertisements

Prev Tutorial Next Tutorial

Structure of C++ Program

Every C++ program can be written with the following syntax.

Syntax

#include<headerfilename.h>  --> include section

class class_name
{
data members;
user defined method;
{
..........
..........
}
};

returntype main()  --> main method
{
.........
.........
}

Include section

# include is a pre-processor directive can be used to include all the predefined method of given header files into current C program before compilation.

Syntax

#include<headerfile.h>

class

Class is a blue print which is containing only list of variables and method.

C++ library is collection of header files, header files is a container which is collection of related predefined method.

User defined method section

If any method is defined by the user is known as user defined method. Method is collection of statement used to perform a specific Operation.

Syntax

returntype method_name()
{
.......
.......
}

In the above syntax method name can be any user defined name, return type represents which type of value it can return to its calling method.

Syntax

methodName();	// calling method

Note: User defined method are Optional in a C++ program.

Main() method

This is starting executable block of any program (it is always executed by processor and OS ). One C++ program can have maximum one main() the entire statements of given program can be executed through main(). Without main() method no C++ program will be executed.

Syntax

returntype main()
{
......
.....
}

If return type is void that method can not return any value to the operating system. So that void can be treated as no return type.

Example

#include<iostream.h>
#include<conio.h>

void main()
{
cout<<("Hello main";
}

Output

Hello main

IO statements in C++

IO represents input output statements, and input statement can be used to read the input value from the standard input device (keyboard), output statement can be used to display the output in standard output device (Monitor) respectively. In C++ language IO statement can be achieve by using cout<< and >>cin.


Prev Tutorial Next Tutorial

Google Advertisment

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

For Projects 9999595223

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements