0% found this document useful (0 votes)
55 views

C++ Presentation

C++ is an object-oriented programming language that extends C and allows for object-oriented programming. It is known as C with classes. C++ allows for declaration of variables anywhere in a scope unlike C, and supports features like inheritance, polymorphism, and overloading that are not present in C. C++ can be used to develop software, build drivers, and create video games and server software.

Uploaded by

Shrey Suri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

C++ Presentation

C++ is an object-oriented programming language that extends C and allows for object-oriented programming. It is known as C with classes. C++ allows for declaration of variables anywhere in a scope unlike C, and supports features like inheritance, polymorphism, and overloading that are not present in C. C++ can be used to develop software, build drivers, and create video games and server software.

Uploaded by

Shrey Suri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27

BASICS OF C++

C++ is a multi-paradigm programming


language that supports object oriented
programming (OOP) .
C++…WHAT IS C++ is actually an extension of C
IT?? programming and the programs written
in C language can run in C++ compiler.

C++ is also known as C with Classes.


DIFFERENCE BETWEEN C AND C++

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

Global Declaration Section


STRUCTURE
OF C++ Class Declaration and Method Section

Main Function

Method Definition Section


MAIN FUNCTION

• main() is the most important function for


C++ programming.
• It is used to define from where the has to
start.
• It has the following two formats
• main() { //body }
• main(int argv, char ** argc) { //body }
SIMPLE PROGRAM C++

#include<iostream.h> //Header File


using namespace std;
int main() /*Main Function*/
{
cout<<"\n*HELLO*\n";
/*Output Statements*/
}
LET’S REVIEW

• #include<iostream.h> is the preprocessor directive.


• // corresponds to single line comments
• using namespace std is used to tell the system to use the standard
functions of the preprocessor directive directly.
• int is a datatype
• cout is used to print the statements following it
• /* is used to start a multiple line comment and */ is used to end that
comment.
Primary data type int, float, char, void
User defined data type structure, union, class,
enumeration
Derived data type array, function, pointer,
reference

C++ DATA TYPES


C++ VARIABLES SCOPE

• 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; }

• In the definition of function parameters which is called formal parameters.


• int function(int a, int b){ //function’s body}

• Outside of all functions which is called global variables.


EXAMPLES

#include<bits/stdc++.h> int main(){

// Local variable declaration:

using namespace std; int a, b;

// actual initialization

int g; // global variable a = 10;

b = 20;

void add(int a,int b){ // formal or function parameters add(a,b);

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

#include<bits/stdc++.h> a=0; b=10;


using namespace std; if(a&&b)
void main()
{ cout<<“condition is true”; }
{
else
int a,b; a=12; b=10;
cout<<“condition is not true”;
if(a&&b)
if(!(a&&b))
{ cout<<”condition is true”; }
{ cout<<“condition is true”; } }
if(a||b)
{ cout<<“condition is true”; }
BITWISE OPERATOR

Bitwise operator works on bits and perform bit-by-bit operation.

P Q P&Q P|Q P^Q

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&B = 0000 1100

A|B = 0011 1101

A^B = 0011 0001

~A = 1100 0011
ASSIGNMENT OPERATOR

An assignment operator, in the context of the C++ programming


language, is a basic component denoted as "=".
int x = 25;
x = 50;
SOME OTHER OPERATORS

• Post-Increment Operator : int a = x++;


Here previous value of x is assigned to a and then, x is incremented.

• Pre-Increment Operator : int a = ++x;


Here value of x is first incremented and then assigned to a;
• Conditional Operator : a==b?true:false;
It is used for a shorter if else statement.
PRECEDENCE

When there are multiple operators in a


statement, precedence is used.
CONDITIONAL STATEMENTS

IF… ELSE IF … ELSE SWITCH


• It is used when you want many if…else statements
• It is used when you want to have some
• Format :
conditions in the code.
switch(variable to consider){
• Format : case 1:

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

For While Do-While


For loop:
It uses a counter variable to work
It’s easier to understand how many times the loop will work.
Ex –
for(int i=0;i<10;i++){ //Statements }

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

• Array is defined as a set of homogeneous data items.


• An Array is a group of elements that share a common name that are
differentiated from one another by their positions within the array.
Syntax
datatype arrayname[array size];

Example: float salary[10];

float  data type


salary  array name
[10]  size of array
• In C++ elements of an array can be initialized one by one or using a single statement.
float balance[5]={1000.0, 2.0, 3.4,7.0, 50};
• The number of values between braces { } cannot be larger than the number of elements that we
declare for the array between square brackets [ ].

• 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

Given integer array:


int arr[6] = {3,6,2,5,7,4};
Find :
• Maximum element in this array
• Minimum element in the array.

You might also like