C++ Presentation
C++ Presentation
C C++
C is Procedural Language. C++ is non-Procedural i.e. Object oriented
Language.
Top down approach is used in Program Bottom up approach adopted in Program
Design. Design.
Multiple Declaration of global variables are Multiple Declaration of global variables are
allowed. not allowed.
C requires all the variables to be defined at the C++ allows the declaration of variable anywhere
starting of a scope. in the scope i.e. at time of its First use.
Memory Allocation - malloc() and calloc() Memory Allocation - malloc() , calloc() and new
Memory Deallocation – free() Memory Deallocation – free() and delete
USES OF C++
Used to develop
Computer Software and Used to build Drivers.
many System Softwares
Creation of Video
Server Softwares.
games.
Header File Declaration Section
Main Function
• A scope is a region of the program and broadly speaking there are three places, where
variables can be declared −
• Inside a function or a block which is called local variables.
• { int a; }
// actual initialization
b = 20;
g = a+b; cout<<g;
} return 0;
}
Arithmetic operators
Relational operators
OPERATORS
Logical operators
Bitwise operators
Assignment operators
ARITHMETIC OPERATORS
#include<bits/stdc++.h> cout<<c;
using namespace std; c=a*b;
void main() cout<<c;
{ c=a/b;
int a,b,c; cout<<c;
cout<<“enter the value for a and c=a++;
b”; cout<<“incrementation of a by one”<<c;
cin>>a>>b; c=a--;
c=a+b;
cout<<c; cout<<”decrementation of a by one”<<c;
c=a-b; }
RELATIONAL OPERATORS
#include<bits/stdc++.h>
using namespace std; if(a<=b)
{ cout<<”a is less than or equal to b”; }
void main()
if(a>=b)
{ { cout<<“a is greater than or equal to b”; }
int a,b; a=10;b=13; if(a==b)
if(a<b) { cout<<”a is equal to b”; }
{ cout<<“a is less than b”; }
if(a!=b)
if(a>b)
{cout<<”a is not equal to b”); }
{ cout<<”a is greater than b”; }
}
LOGICAL OPERATORS
0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0
Assume if A = 60; and B = 13; now in binary format they will be as follows:
A = 0011 1100 ----> Binary Number for 60
B = 0000 1101 ----> Binary Number for 13
So, we get:
~A = 1100 0011
ASSIGNMENT OPERATOR
if(condition 1) Statements
break;
{ Statements }
case 2:
else if( condition 2) Statements
{ Statements } break;
default:
else
Statements
{ Statements } break;
}
#include<bits/stdc++.h>
using namespace std;
int main(){
int a = 2;
switch(a){
case 1:
cout<<1<<endl;
case 2:
cout<<2<<endl;
WHAT IS THE case 3:
OUTPUT?? cout<<3<<endl;
case 4:
cout<<4<<endl;
default:
cout<<a<<" >=5"<<endl;
}
return 0;
}
Loop
While loop:
It uses conditions to work
It’s not as easy to understand how many times the loop will work.
Ex –
while(i<10) { //Statements }
Do-while loop:
In it the loop always work for a single time, after which the condition is checked.
Ex –
do { //Statements }while(i<10);
ARRAYS
• But the values inside the brackets can be less than the size of the array.
float balance[5]={1000.0, 2.0, 3.4,7.0, 50};
What will the value of rest??
• Array elements can be accessed (for updation or checks) using array_name[index];
• Array indexes starts form ‘0’ and end at ‘array_size – 1’
LET’S CHECK