A SAMPLE PROGRAM IN C++

Sample program in C++

A SAMPLE PROGRAM IN C++

Now, we will be going to study and explore about​ C++ Programs. But, before beginning the programs.. Let’s begin our journey to the C++ programs with a short Sample Program in C++.. Generally, for an easy start.. The sample program will print or display a general message on the screen.

Below is the sample program in C++,

#include<iostream.h>        //Header file for C++ program

int main( )

{

cout<<“THIS IS A SAMPLE C++ PROGRAM”<<endl;       //The message is in between double quotes (” “). And, “endl” is for a new line.

return 0;

//END OF THE SAMPLE C++ PROGRAM

}

OUTPUT OF THE PROGRAM :

THIS IS A SAMPLE C++ PROGRAM

Certainly, This Sample C++ program demonstrates various C++ features which we were discussing in the previous post. Furthermore, let’s discuss the above C++ program in detail..

PROGRAM FEATURES

As we all can see, the above program looks much different from the C Programs. A line-by-line commentary is much useful for the user for understanding the code effectively. Furthermore, the first feature is the header i.e. <iostream> which includes in the program.

THE IOSTREAM FILE :

#include<iostream.h>

First of all, there is an inclusion of the file “iostream.h“. The first character is the # symbol, which is generally a signal to the preprocessor.. Furthermore, each and every time we start the compiler, the preprocessor runs.

Certainly, the preprocessor reads through the source code of the program.. And, it looks for the lines that begin with the hash symbol (#). Also, it also acts on those lines before the compiler runs.

Now, include is a preprocessor instruction that means.. “WHAT FOLLOWS IS A FILENAME, FIND THAT PARTICULAR FILE AND READ IT IN RIGHT HERE”. Furthermore, the Angle brackets around the file name tells the preprocessor.. “TO LOOK IN EVERY USUAL PLACES FOR THIS PARTICULAR FILE.”

Also, if your file is set up correctly, then the angle brackets prepares the preprocessor to.. “look for the file iostream.h in the directory that holds each and every “.h” files for the compiler.”

Leave a comment

Your email address will not be published. Required fields are marked *

10 thoughts on “A SAMPLE PROGRAM IN C++”