News:

Choose a design and let our professionals help you build a successful website   - ITAcumens

Main Menu

Structure and features of C++

Started by sukishan, Jul 10, 2009, 09:45 PM

Previous topic - Next topic

sukishan

Structure of the C++ Program and C++ features

Above program demonstrates several important features of C++ language. The structure of the program above is as follows:-

// This is my first C++ program

//It prints a line of text

are comments in C++ language.

# include <iostream>

is a preprocessor directive. It tells the preprocessor to include the contents of iostream header file in the program before compilation. This file is required for input output statements.


main Function

int main()

is a function. C++ program is a collection of functions. Every program in C++ begins executing at the function main(). Every C++ program has exactly one main function and a collection of other functions.

A function is the main entity where all of the functionality of a program is defined. A function takes some input, processes it according to the some code written in the function body and produces an output which can be either sent to the user or can be used by other functions.

Keyword int in int main()

specifies the return type of a function. int specifies that the function main returns an integer value.

Brackets () after main signify that main is a function. Every function should be followed by a pair of brackets. The purpose of brackets is to pass the parameters list to the functions. Parameters are the number and type of arguments (inputs) which a function takes.

Opening brace ( { ) and closing brace ( } ) mark the beginning and end of a function. Anything which is inside the braces is the body of that function.

In our example, the function body consists of only two statements,

{

std::cout << "My first C++ program. \n";

return 0;

}
A good beginning makes a good ending

Quick Reply

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it has been approved by a moderator.

Name:
Email:
Verification:
Please leave this box empty:
Type the letters shown in the picture
Listen to the letters / Request another image

Type the letters shown in the picture:

Shortcuts: ALT+S post or ALT+P preview