C++ Language


What is C++ Language ?
C++ is a general-purpose object-oriented programming(OOP) language and it is also high level programming language.

Syntax for C++ :
#include<iostream.h>
using namespace std;
int main(){
cout<<"Hell World";
}

Explanation :
1. iostream : It is a standard library function.
2. << : Extraction operator.
3. >> : Insertion operator.
4. using namespace std : If we once defined a std using namespace within the code then no need to write everytime.
5. endl : It is used for next line.

Pros and cons of C++ :

Pros :
1. Wide support
2. Powerful 
3. Speed
4. Small standard library

cons :
1. Unsafe
2. Littile memory management
3. Complicated
4. Syntatically strict

Use of C++ :
1. Windows application
2. Client-Server application
3. Embedded firmware

Main differenace between C & C++ :

C C++
Scanf used for input and Printf used for output Cin used for input and Cout used for output
In this varibles are declared starting of the main function its not possible to declare anywhere of the program. The varibles are declared anywhere of the program.
Reusability is less. Reusability is more.
In this we use memory allocation and deallocation malloc(), calloc() & free() In this we use memory allocation and deallocation new and delete.
Name space feature is not supported. Name space feature is supported.
C is function driven language. C++ is objict driven language.
Top down approch is used in this program. Bottom up approch is used in this program.
Multiple declaration of global variable is allowed. Multiple declaration of global variable is not allowed.
Exception handling is not possible. Exception handling is  possible..


Example program to print a name :







Use of scope resolution operator(::) :
It is used to define a function outside a class or when we want to use a global variable but also has a local variable with the same name. 

Ex :




To display a string :





Use of cin.get( ) function :
By using this function we eliminate the spcing in string.

To display a string :



Use of getline( ) function and string object :
string object is used to holding the strings.







Using function :







Ex :





Using single dimensional array to print strings :





Using multidimensional array :






To print numbers in ascending order :









To print numbers in descending order :






To find largest number and samllest number :








OOPS concept in C++ :

Object means real world entity. The OOPS(Object Oriented Programming Language) is a methodology to design a program using classes and objects. It simplifies the software development and maintenance by providing some concepts.



Class : 
Class is a logical entity. It is the collection of Objects. Which is accessed by the Object.

Object :
Object is the physical entity. The main purpose of object is to access the class.

Inheritance :

logoblog
Previous
« Prev Post