Let us create a simple 'Hello, World' program... Now just type what you see on the picture in your compiler, and later we will analyze it...
Source code :
COMMENTS : Comments are those lines in a program which the compiler ignores. In our hello world program, you can see many comment lines on the right side of each line, in dark blue color. Comments can be used for teaching, reminding yourself, and also it is an important part in readability. There are two types of comments :
Source code :
After entering the code, you should compile and run your program using your compiler. In the case of Turbo C++ 4.5, for running, press ctrl+F9 or Debug --> Run
Output:
No let us look at the structure of the code..
#include<iostream.h> : This line is to link the program to be run, to a specific file called Header File, in which there are information about things to be done in the program. We will learn about this later...
void main() : This line is called a 'function'. It actually says the compiler that this is where the Program execution should begin. We will learn much more about Fuctions, in coming lessons.
{ & } : Opening and closing curly brackets are the starting, and stopping point of a function.
cout : Input and output (I/O) operators are integral parts of any programming language. They are the interactive parts of a language. A language without I/O Operators are like a human body without any senses (blind, cannot smell, deaf, dumb, insensitive to the skin)... Whoo! Can't even imagine right? "cout" is one of the output operator of C++ ... That means, cout displays text in the output. Notice that after cout, there are two "<<" less than signs. (NOT ">>"). General form of cout is : | cout<<"text to be displayed"; | Also note that, the operator ends it's line with a semicolon ";". Now try displaying your name in the place of "Hello World" in your program. We will learn many I/O Operators in coming days.
1. Single line comments - They are those which start with two front slashes "//" These can only be used for commenting in a single line. Their general form is | //commentcontent |
2. Multiple line comments - Those which start with a front slash and a star and ends with a star and a front slash, are multiple line comments. These can be used to type many lines and paragraphs. The compiler wont even look inside those "/*" and "*/" ! General form is : | /* comment content no limitsssss! */ |
But there are some limitations for WHERE to use multiple line comments. For example, it cannot be used in such a way: | for(i=0;i<n /* Comment invalid */ ; i++) | i.e inside a loop (later, I promise... ;) )
In next lesson, we will learn about input functions, where we can INPUT our own values to the program, operators in C++, and EXCLUSIVE : WE ARE GONNA MAKE A SIMPLE CALCULATOR!!! Excited huh??? See you next time...
Happy Coding.. :)