Structure of C++ program

In our last post we have introduced you to the object oriented programming.Today we shall know about the structure of c++ program.The structure of c++ program mainly divided into three parts.

1.Header files
2.Declaration of classes
3.main function
Let us go in detail about all these sections.Starting with Header file section.

1.Headers Files: As we know that all the commands in any compiler are divided into two types. They are User defined and pre-defined words. For user defined words user should specify compiler about the meaning of the command.Pre-defined words are defined in the library files of the compiler.Therefore we need to include header files which defines the word.For any c++ program we should include iostream.h header file at the beginning of the program. There are some many header files and they are included depending upon the usage of the keywords in the program.

2.Declaration of classes: We know that class is the main feature of the object oriented programming.In c++ program we need to declare all classes before main function.Though many classes are needed in the program we need to declare all these classes before main function.A class may contain data members and member-functions,therefore we need to define these member functions before the main function.

3.Main function: Main function of program is like heart of our body. Though a program may contain 100 functions compiler checks for main function in the program. All our program will be executed depending upon the order of commands specified in the main functions. Following is a sample program to explain you structure of c++ program.

#include iostream.h //Header file part//
class A //Class declarations//
{
void display()
{
cout<<"Let us learn Programming":
}
};

void main() //Main function//
{
A ob;
ob.display();
}

Advertisements

About Anuroop D

Very enthusiastic about technology and likes to share my knowledge through blogging. Has Bachelor's in Information Technology and currently pursuing my Master's in Computer Science.
This entry was posted in C++ and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s