C Basic Introduction (Continued..) – A look at first C++ Program
Line 1: // My First C++ Program
Line 2: #include<iostream.h>
Line 3: int main()
Line 4: {
Line 5: cout<<"Welcome To Your First Program";
Line 6: return 0;
Line 7: }
The program is the simplest program and includes some of basic elements that every program mainly have.
Lets have a look on these basic elements –
Line 1: //My First C++ Program
This is a comment. lines begin with // are comments. These are the pieces of code that compiler never executes.
Purpose- It allows the programmer to insert some notes or descriptions to enhance readability or understandability of the program.
There are two ways in C++ to insert comments –
- Single Line Comments – By // . Compiler simply ignores any line begining with // in that same line.
- Multiline or block comments – Everything between /* …… */ is considered as a comment. These are the block comments i.e. everything that falls between /* ….. */ is considered a comment even though it is spread across many lines.
// My First C++ Program
#include<iostream.h>
int main()
{
cout<<"Say Hello to Your First Program"; /* This is a simple
program having one
output statement
for the purpose of
explaining comments.
*/
return 0;
}
Line 2: #include<iostream.h>
Line 3: int main()
Line 4 to Line 7 :
]]>