C++ program and its component

C++ program and its component

C++ program and its component
#include <iostream.h>
void main()
cout <<” A C++ program and its component”;
Despite its small size, this program demonstrates a great deal about the construction of C++ programs. Let’s discuss it in detail.

// A C++ program and its component

This is the first line in the above program. (//) is a comment symbol. Comments do not have any effect on the behavior of the program.Comments can be used to include short explanations or observations within the source itself. In this first programming demo at a first line “// A C++ program and its component” is a comment section.

#include <iostream.h>

The sign (#) is a directive for the preprocessor. It is not executable code line but indications for the compiler. The line of code “ #include <iostream.h>” tells the compiler’s preprocessor to include the iostream standard header file.
This specific file includes because its functionality is used later in the program. This file includes the declarations of the basic standard input-output library in C++.

void main()

When you run a C++ program, the first statement executed will be at the beginning of a function called main(). The program may consist of many functions, classes, and other program elements, but on startup control always goes to main(), If there is no function called main() in your program, the linker will signal an error. In most C++ program main() calls member function in various objects to carry out the program’s real work. void is return type of the function. void tells that there is no return type of the function.

Braces and the function body “{ }”

The body of the function is surrounded by braces (sometimes called curly brackets). These braces play the same role as the BEGIN and END keywords in Pascal and BASIC. They surround or delimit a block of program statements. Every function must use this pair of braces. In the above example there is only one statement within the braces: the line starting with cout. However, a function body can consist of many statements.

cout << ” A C++ program and its component”;

cout is the standard output stream in C++ programs. It is declared in the
iostream.h header file, so in order to be able to use it that file must be included.
This statement displays “A C++ program and its component”.
The operator << is called the insertion or put to operator. It directs the contents of the variable on its right to the object on its left. In First it directs the string constant ” A C++ program and its component” to cout, which sends it to be display.
Note that the sentence ends with a semicolon character (;). If you forget to use it, there will give an error.
String Constants (“A C++ program and its component”)
“A C++ program and its component
” is an example of a string constant. As you probably known, a constant, unlike a variable, cannot be given new values as the program runs. Its value is set when the program is written, and remains this value throughout the program’s existence.
On the one hand there is no real string variable type; instead you use an array of type char to hold string variables. On the other hand C++ recognizes string constants, surrounded by quotation marks.

Leave a Reply

Your email address will not be published.