I am beginning a series of articles about C++ programming language. So lets begin with a simple C++ program as shown below.
#include
int main()
{
cout<<"My first C++ code"<<"\t"; // This is a C++ comment
return 0;
}
This piece of code when executed, outputs a line of text " My first C++ code" on your computer screen. Lets analyse this piece of code in detail.
- iostream.h - is called a header file
- main() - is called a function
- cout - is called an identifier
- << - is an output operator called as "insertion" or "put to" operator
- #include - is called a preprocessor directive
- int - is called a data type that represents an integer data
- return - is a keyword in C++ , used to return values to a particular function
Lets begin with main() function:-
int main(){function code blocks;return 0;}
Analyzing the statement beginning with cout<<
cout<<"My first C++ code"<<"\t"; // This is a C++ comment
cout is an identifier (pronounced as C out) that represents the standard output stream. cout is a predefined object in C++, which represents the standard output stream and it's declaration is given inside the header file iostream.h. Usually the output stream will be your computer monitor.
<< is known as the insertion operator (or put to operator). It inserts contents in its right side to the object in its left side.
\t - is an escape sequence which prints a tab space on the output monitor. Similalry \n is another escape sequence which prints a new line on the output monitor.You can read more about escape seuqnces here:- Escape seuqnces in C.
\\ (double slash) is a symbol for representing comments in a C++ program. \\ is usually used to represent a single line of comment. For representing multiple line of comments we may use the comment symbol of C programming language /* */
# is a preprocessor and include is a preprocessor directive. iostream.h is the header file that contains declarations of identifiers like cout, cin and operators like << and >>
Note:- If you are new to programming using C/C++ - you may find it a little confusing to RUN the above program. You may read this article first to get a good idea of "how to run your first C/C++ program" :-
After reading the above article, try running this code:-
#include
#include
int main()
{
cout<<"My first C++ code"<<"\t"; // This is a C++ comment
getch(); /* Function to hold the ouput screen "PAUSED" until we press a key*/
return 0;
}

3 Comments
“return 0” in “main” doesn’t imply that 0 is returned to “main”. Actually, this value is returned to the operating system ( 0 usually means that the process exited normally).
hi i want to to do my first programming and i am a beginner.please tell me what i need for this like programming board etc
hi i want to to do my first programming and i am a beginner.please tell me what i need for this like programming board etc…..reply asap.