#include <iostream.h>void main(){ cout<< "Welcome to C++";}
This is the first program which you
will be studying in a programming
language, this
is your very first C++program because this
program is the simplest of all C++ programs as it only prints the sentence
“welcome to C++”on the screen And then exits.
Now I will explain this program line by line if you understand this program the way I am thinking you would then I guess you will learn C++ at a much better rate .so try to understand the concept as much as you can. #include <iostream.h>
All
lines starting by # are
preprocessor directives. It commands the compiler that it has to include all
the functions and variables present in the file iostream.h in the program well
I know what you are thinking what is this function? Well for now take it as a
special command made by the user or making programming easy and in iostream.h
there are a number of such functions available.Iostream stands for input and output
stream about which we will learn later..
void main()
it
is the main function definition not the prototype please just try to remember
it for now till we reach functions just understand the concept that the main
function is the most important and the only function that is executed
automatically .this function is actually called or executed by the operating
system for us. The main function is the module where the main coding is done
but every program needs to be executed otherwise it will not execute the
statements inside it and this calling the function is done by the operating
system. We will learn about this in detail in functions as it for now just try
to understand what I have told till now.
{
It
is the starting of the body of
the main function.
cout<< "welcome to C++";
This
is the statement inside the main function. It prints Welcome to C++on the console output device i.e.
the monitor. For performing this function we use the command cout which stands
for console output .the compiler send the words inside the double inverted
commas to the monitor for printing it. This command cout is actually defined in
the file iostream.h which is included in the starting so that the functions
like cout,cin etc are executed and do not produce an error..
Lastly, the line
}
Marks
the end of the body of the main function.
Do not worry if you do not understand everything right now; this was just
a overview of how a simple
program works.
The smallest C++ program
Here it is
void main(){}this program only executes the main function only but it is to be noted that no statements are present in the braces so no code is executed the only thing happening in this program is that the main function is started and then exited that’s it. wow now I can say we learnt something today baby theirs more to it and hey presto if you find this exiting then hang on tight because it is gonna be a bumpy ride.