If you want to learn the C++ programming language, then you are the right place. Here you will provided all the basics of writing C++ program and about the lines and statements used in a program. so let's begin...
What is C++ ?
C++ was developed by Bjame Stroustrup in 1979 at the Bell Laboratory. It is a middle level programming language.
C++ is an object oritented programming language and it is also easy to understand. After learning it is easy to learn other languages like java, python, etc.
C++ is used to develop games, OS (operating systems), browsers and so on because of its better performance.
C++ also helps you to understand the internal architecture of a computer, about how the computer stores and retrieves the information.
Writing the " Hello World " program is the very first step for learning any programming language and it is also one of the simplest programs. You just have display the statement of " Hello World " on the output screen. lets us begin to look at the program :
Line 1: // my first program of C++
In the above line two slashes are given before a line, which shows that the given line will have no effect on the behaviour of the given program. These two slashes are given to comment out something on a particular program. It is given for the short explanations about what the program is about, and all about the codes written on it.
Line 2: #include <iostream>
The lines that are beginning with a hash sign (#) are directives read and interpreted, which are known as the pre-processor. They are the special lines that are interpreted before the compilation of the program begins. In the given case, the directive #include <iostream>, gives the instruction to the pre-processor to include a section of standard C++ code, known as the header iostream, which allows it to perform the standard input and output operations on the given program.
Line 3: A blank line.
The blank lines given don’t have any effect on the program. It is just to improve the readability of the program to the reader.
Line 4: int main ()
The lines written in this format are known as the functions. A function is a set of group of statements, which is written in form of the syntax given below:
Syntax : datatype function name (arguments if need)
Here in this case it is (int main ( )). A function named (main) is known as a special function in all the C++ programs. The execution of all the programs starts from the main function.
Lines 5 and 7: { and }
The open curly bracket ( { ) shows the beginning of the main’s function body, and the closing curly bracket ( } ) shows the ending of the main function. Inside these brackets the main function body is written, which will define what will happen when the function will be called. All the functions uses these curly braces at the beginning and at the ending of their body.
Line 6: cout << "Hello World";
This line is a statement in C++. The cout can be known as predefined object of ostream class. It is connected with the output device that is usually a display screen. The statement written with cout using the operator ( << ), prints the statements as it is written on the console. The statement ends with semicolon ( ; ). This character shows the end of the statement. In C++ every statement should end with a semicolon.
Cin>>
The cin is also a predefined object of the ostream class. It is connected with the with a standard input device that is usually a keyboard. The statement is written as cin with operator ( >> ) to read the input from the console.
Using namespace std
In the programs that you have seen C++ code previously, you might have seen cout being utilized rather than std::cout. Both name a similar object: the first purposes its unfit name (cout), while the second qualifies it straight forwardly inside the namespace std (as std::cout).
cout is important for the standard library, and every one of the components in the standard C++ library are declared inside what is known as a namespace: the namespace std.
To allude to the components in the std namespace a program will either qualify every single use of components or elements of the library (as we have shown by prefixing cout with std::), or present visibility of its parts. The most normal method for presenting visibility of these parts is through using the declarations.
This is the basic syntax of writing any program in C++. Hope you all have understand the above syntax and about its working.
3 Comments
Gud
ReplyDeleteMst
ReplyDeleteBest article
ReplyDelete