Friday, April 26, 2019

Understanding C++ BASICS With Sample Program | Including Exercises |

C++ Basics
Understanding C++ BASICS With Sample Program | Including Exercises  | Today I am going to tell you some basics about C++ language.It's computer language used to create programs.It's an updated version of C Language.It is used to create Programs, Windows Console Applications etc.It's a basic language which programmers learn in starting of their career.

• instruction of a C++ program • e.g. cout  → displays a result on monitor cout << “Welcome to C++” Output on monitor:

Welcome to C++
performs some special task in a program


• Special programs, which are part of compiler 
• Support statements & functions in a program 
• 2 important libraries, required when enter data from keyboard or get result on monitor: - iostream (input output stream) - conio.h (console input output header) [header is an extension to header file, given in some libraries] 
Preprocessor Directive
• Instructions to a compiler to add a library in a program • #include • e.g.  #include <iostream>

Reserving an area in RAM for a C++ Program

using namespace std • Reserves an area with the name std (standard) • Given between ‘libraries’ and ‘void (main)’
Program & Output Windows Program Window When program is entered, saved, compiled & run, we are in Program Window, where we can see our program list Output Window To check results, we have to go from Program Window to Output Window by using a function: getch()

Structure of a C++Program 

#include …… : 
: using namespace std;
 void main()       
Start of program {                  
 C++ statements & functions;     
}      End of program

Program to display a message on monitor

using namespace std; 
void main() 

cout << "Welcome to C++";

Write a C++ program to display your name on monitor
Display Result in one line

cout  << “This result” ; 
cout  << “is in the” ; 
cout  << “same line” ; 
Output This result is in the same line
Display Result in next line


cout << “This result” ; 
cout << “\n is in” ;
 cout << “\ndifferent lines” ; 
Output This result is in different lines here n is called new line character

• Exercise 1 

Write a program which will display following result on monitor: 
Reg-no    Name    Class    University-name 
• Exercise 2 
Write the above program to display 
Regno, Name, … in separate lines
r.So without any further delay let's get started.