Structure of a C++ Program
How to write a C++ Program?
The following are the normal format to write a CPP program.
1) Documentation: it contains the details or meta data (Data about data) of a program like developer, to whom the program is writing, what the program is etc. etc...
example:
/*
Program to find the sum of 2 integer variables
programmed by Satheesh Kammath R
this program is writing for my students
*/
2) Include section: This includes header files for our program. Header files are the file which contains pre defined variables and functions used for our program. Normally this file will be stored in INCLUDE directory(folder) with the extension .h
example:
#include "" (" cannot be used). # symbol is known as pre processor directive. because this instruct the compiler to include the specified header file into our program before the main process starts.
we can also create our own header files for our later use.
3) Global Variable/Function Section: this contains variable declared for global use(for entire program) means the variable or functions declared here can be accessed from any part of the program.
example:
const float pi = 3.14;
char title[]="Satheesh Kammath R"
void display(void); //declaration only - also called function prototype
4) Main section: this is the entry point of every C++ program. this function should be named as main followed by ().
and then followed by the program code which is to be written inside the main function.
example:
int main()
{
int n;
cout << "Enter a number ";
cin >> n;
cout << "Your number is " << n << endl;
}
5) function definition section
the body or process of the function is writing here with declaration
example:
void display(void)
{
cout << "Welcome to the world of C";
cout << "Hello World";
}
In the above given sections
section 1, 3, 5 are optional, means it is not compulsory to write these section to run cpp program.
that strongly impose that other sections, 2 4 are important to execute a cpp program.
hope make it sense...
if any doubts or clarifications please comment or email to skrtvm@gmail.com
The following are the normal format to write a CPP program.
1) Documentation: it contains the details or meta data (Data about data) of a program like developer, to whom the program is writing, what the program is etc. etc...
example:
/*
Program to find the sum of 2 integer variables
programmed by Satheesh Kammath R
this program is writing for my students
*/
2) Include section: This includes header files for our program. Header files are the file which contains pre defined variables and functions used for our program. Normally this file will be stored in INCLUDE directory(folder) with the extension .h
example:
#include "
we can also create our own header files for our later use.
3) Global Variable/Function Section: this contains variable declared for global use(for entire program) means the variable or functions declared here can be accessed from any part of the program.
example:
const float pi = 3.14;
char title[]="Satheesh Kammath R"
void display(void); //declaration only - also called function prototype
4) Main section: this is the entry point of every C++ program. this function should be named as main followed by ().
and then followed by the program code which is to be written inside the main function.
example:
int main()
{
int n;
cout << "Enter a number ";
cin >> n;
cout << "Your number is " << n << endl;
}
5) function definition section
the body or process of the function is writing here with declaration
example:
void display(void)
{
cout << "Welcome to the world of C";
cout << "Hello World";
}
In the above given sections
section 1, 3, 5 are optional, means it is not compulsory to write these section to run cpp program.
that strongly impose that other sections, 2 4 are important to execute a cpp program.
hope make it sense...
if any doubts or clarifications please comment or email to skrtvm@gmail.com
Labels: Love C++


1 Comments:
wah supper excellent so now onwards we can sent doubt
Post a Comment
Subscribe to Post Comments [Atom]
<< Home