SlideShare a Scribd company logo
1 of 42
Operators in C++
Operators
Overview
1. Arithmetic Operators
2. Increment and Decrement Operators
3. Assignment Operators
4. Relational Operators
5. Logical Operators
6. Bitwise Operators
7. Other Operators
Arithmetic Operators
 +  Addition
 -  Subtraction
 *  Multiplication
 /  Division
 %  Modulo Operation
Increment and Decrement Operators
 ++  Increment operator
 --  Decrement Operator
Assignment Operators
Operator Usage
 = x=y  x=y
 += x+=y  x=x+y
 -= x-=y  x=x-y
 *= x*=y  x=x*y
 /= x/=y  x=x/y
 %= x%=y  x=x%y
Relational Operators
Operator Usage
 == x==y  x equal to y
 != x!=y  x not equal to y
 > x>y  x greater than y
 < x<y  x lesser than y
 >= x>=y  x greater than (or) equal to y
 <= x<=y  x lesser than (or) equal to y
Logical Operators
Operator Usage
 && Exp 1 && Exp 2  Logical AND (Return true if both are true)
 || Exp 1 || Exp 2  Logical OR (Return true at least one true)
 ! ! Exp 1  Logical NOT (Return true if Exp false)
Bitwise Operators
Operator Name
 & Binary AND
 | Binary OR
 ^ Binary XOR
 ~ Binary One’s Complement
 << Binary Shift Left
 >> Binary Shift Right
Decimal to Binary
Binary to Decimal
Binary to Decimal
Bitwise AND Operator
Truth Table Example Code:
Output :
Formula:
Bitwise OR Operator
Truth Table Example Code:
Output :
Formula:
Bitwise XOR Operator
Truth Table Example Code:
Output :
Formula:
Bitwise Complement Operator
Table Example Code:
Output :
Formula:
Flow Chart:
Right Shift Operator
Flow Chart:
Example Code:
Output :
Formula:
Left Shift Operator
Flow Chart:
Example Code:
Output :
Formula:
Loops
• for
• while
• do...while
• break
• continue
• switch
• goto
For loop
Syntax: Flow Chart:
Example Code:
How it works:
Output:
While Loop
Syntax: Flow Chart:
Example Code:
How it works:
Output:
Do While Loop
Syntax: Flow Chart:
Example Code:
How it works:
Output:
Arrays in C++
 One Dimensional Array
 Two Dimensional Array
One Dimensional Array
 Declaration : dataType arrayName[arraySize];
 Ex, int a[10];  int (datatype) a (arrayname) [10] array size
Two Dimensional Array
int x[2][3] = { {2, 4, 5}, {9, 0, 19}};
String
Declaration :
 char x[100] = “Hello";  Char – Datatype; x  String Name;[100]  String Array Size
Sample Program
 #include <iostream>
 using namespace std;
 int main()
 {
 char str[100];
 cin.get(str, 100);
 cout << str << endl;
 return 0;
 }
Functions
 Pre-defined Functions
 User-defined Functions
 Call By Value
 Call By Reference
User Defined Functions
Call by value example code:
Output:
Call by reference example code:
Output:
C++ Recursion
Structure Flow
Pointers
What is pointer?
 Pointer reduces the code and improves the performance, it is used to retrieving strings,
trees etc. and used with arrays, structures and functions.
 We can return multiple values from function using pointer.
 It makes you able to access any memory location in the computer's memory.
Pointers
Usage of Pointer
Dynamic memory allocation
 In c language, we can dynamically allocate memory using malloc() and calloc() functions
where pointer is used.
Arrays, Functions and Structures
 Pointers in c language are widely used in arrays, functions and structures. It reduces the
code and improves the performance.
Declaring a Pointer
We use the asterisk (*) symbol to designate a variable as a pointer in C++. The
asterisk symbol can be placed anywhere before the pointer name and after the
datatype.
Syntax :
If we have to declare two (or more) pointers together in the same line, we will need
to use the asterisk symbol before each variable name. For example:
Pointer Example
Printing Address & Value of the variable using Pointer Output
Pointer Example
Program to swap 2 numbers without using 3rd variable Output
Double Pointers
What is double pointers?
 Regular pointer is to refer to an object in memory, then a double pointer is a variable that points to
another pointer which in turn, points to an object in memory.
 Double pointer is also known as pointer to pointer.
Declaring Double Pointers
Declaring a Pointer to a Pointer in C++ or double-pointer is very similar
to declaring a single pointer; the only difference is that an extra * is
added.
For Example
Syntax :
Double Pointers Example
The simple working of double pointer Output
New & Delete Operator
The “new” operator is used to allocate memory for a
variable or any other entity like objects or arrays on a
heap memory area. If a sufficient amount of memory
is available on the heap, the new operator will
initialize the memory and return the address of the
newly allocated memory and you can use pointers to
store the address of that memory location.
Output
Example
Since the programmer has allocated memory at
runtime, it’s the responsibility of the programmer to
delete that memory when not required. So at any
point, when programmers feel a variable that has
been dynamically allocated is no anymore required,
they can free up the memory that it occupies in the
free store or heap with the “delete” operator. It
returns the memory to the operating system. This is
also known as memory deallocation. Also, memory
Class
 Description & Structure :
A class is a blueprint for the object.
We can think of a class as a sketch (prototype) of a house. It contains all the details about the floors,
doors, windows, etc. Based on these descriptions we build the house. House is the object.
Objects
 Description & Structure :
When a class is defined, only the specification for the object is defined; no memory or storage is
allocated.
To use the data and access functions defined in the class, we need to create objects.
Class & Objects Sample
 Program :

More Related Content

Similar to C++.pptx (20)

C++ tutorials
C++ tutorialsC++ tutorials
C++ tutorials
 
C++
C++C++
C++
 
c-programming
c-programmingc-programming
c-programming
 
Introduction to Client-Side Javascript
Introduction to Client-Side JavascriptIntroduction to Client-Side Javascript
Introduction to Client-Side Javascript
 
Operators
OperatorsOperators
Operators
 
Programming in C sesion 2
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2
 
Pointers
PointersPointers
Pointers
 
Object Oriented Programming Short Notes for Preperation of Exams
Object Oriented Programming Short Notes for Preperation of ExamsObject Oriented Programming Short Notes for Preperation of Exams
Object Oriented Programming Short Notes for Preperation of Exams
 
Basic concept of c++
Basic concept of c++Basic concept of c++
Basic concept of c++
 
Operators
OperatorsOperators
Operators
 
C sharp part 001
C sharp part 001C sharp part 001
C sharp part 001
 
Java chapter 3
Java chapter 3Java chapter 3
Java chapter 3
 
Data structures
Data structuresData structures
Data structures
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Python-review1.ppt
Python-review1.pptPython-review1.ppt
Python-review1.ppt
 
Programming presentation
Programming presentationProgramming presentation
Programming presentation
 
2 EPT 162 Lecture 2
2 EPT 162 Lecture 22 EPT 162 Lecture 2
2 EPT 162 Lecture 2
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)
 
C
CC
C
 

Recently uploaded

Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxEmmanuel Dauda
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxolyaivanovalion
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998YohFuh
 
定制英国白金汉大学毕业证(UCB毕业证书) 成绩单原版一比一
定制英国白金汉大学毕业证(UCB毕业证书)																			成绩单原版一比一定制英国白金汉大学毕业证(UCB毕业证书)																			成绩单原版一比一
定制英国白金汉大学毕业证(UCB毕业证书) 成绩单原版一比一ffjhghh
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptxAnupama Kate
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxolyaivanovalion
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfMarinCaroMartnezBerg
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts ServiceSapana Sha
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxolyaivanovalion
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
BabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxBabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxolyaivanovalion
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz1
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptxthyngster
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfLars Albertsson
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFxolyaivanovalion
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxolyaivanovalion
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptSonatrach
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...Suhani Kapoor
 

Recently uploaded (20)

Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptx
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptx
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998
 
定制英国白金汉大学毕业证(UCB毕业证书) 成绩单原版一比一
定制英国白金汉大学毕业证(UCB毕业证书)																			成绩单原版一比一定制英国白金汉大学毕业证(UCB毕业证书)																			成绩单原版一比一
定制英国白金汉大学毕业证(UCB毕业证书) 成绩单原版一比一
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptx
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdf
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts Service
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptx
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
 
BabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptxBabyOno dropshipping via API with DroFx.pptx
BabyOno dropshipping via API with DroFx.pptx
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signals
 
E-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptxE-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptx
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdf
 
Halmar dropshipping via API with DroFx
Halmar  dropshipping  via API with DroFxHalmar  dropshipping  via API with DroFx
Halmar dropshipping via API with DroFx
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
 
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
 

C++.pptx

  • 2. Overview 1. Arithmetic Operators 2. Increment and Decrement Operators 3. Assignment Operators 4. Relational Operators 5. Logical Operators 6. Bitwise Operators 7. Other Operators
  • 3. Arithmetic Operators  +  Addition  -  Subtraction  *  Multiplication  /  Division  %  Modulo Operation
  • 4. Increment and Decrement Operators  ++  Increment operator  --  Decrement Operator
  • 5. Assignment Operators Operator Usage  = x=y  x=y  += x+=y  x=x+y  -= x-=y  x=x-y  *= x*=y  x=x*y  /= x/=y  x=x/y  %= x%=y  x=x%y
  • 6. Relational Operators Operator Usage  == x==y  x equal to y  != x!=y  x not equal to y  > x>y  x greater than y  < x<y  x lesser than y  >= x>=y  x greater than (or) equal to y  <= x<=y  x lesser than (or) equal to y
  • 7. Logical Operators Operator Usage  && Exp 1 && Exp 2  Logical AND (Return true if both are true)  || Exp 1 || Exp 2  Logical OR (Return true at least one true)  ! ! Exp 1  Logical NOT (Return true if Exp false)
  • 8. Bitwise Operators Operator Name  & Binary AND  | Binary OR  ^ Binary XOR  ~ Binary One’s Complement  << Binary Shift Left  >> Binary Shift Right
  • 12. Bitwise AND Operator Truth Table Example Code: Output : Formula:
  • 13. Bitwise OR Operator Truth Table Example Code: Output : Formula:
  • 14. Bitwise XOR Operator Truth Table Example Code: Output : Formula:
  • 15. Bitwise Complement Operator Table Example Code: Output : Formula: Flow Chart:
  • 16. Right Shift Operator Flow Chart: Example Code: Output : Formula:
  • 17. Left Shift Operator Flow Chart: Example Code: Output : Formula:
  • 18. Loops • for • while • do...while • break • continue • switch • goto
  • 19. For loop Syntax: Flow Chart: Example Code: How it works: Output:
  • 20. While Loop Syntax: Flow Chart: Example Code: How it works: Output:
  • 21. Do While Loop Syntax: Flow Chart: Example Code: How it works: Output:
  • 22. Arrays in C++  One Dimensional Array  Two Dimensional Array
  • 23. One Dimensional Array  Declaration : dataType arrayName[arraySize];  Ex, int a[10];  int (datatype) a (arrayname) [10] array size
  • 24. Two Dimensional Array int x[2][3] = { {2, 4, 5}, {9, 0, 19}};
  • 25. String Declaration :  char x[100] = “Hello";  Char – Datatype; x  String Name;[100]  String Array Size
  • 26. Sample Program  #include <iostream>  using namespace std;  int main()  {  char str[100];  cin.get(str, 100);  cout << str << endl;  return 0;  }
  • 27. Functions  Pre-defined Functions  User-defined Functions  Call By Value  Call By Reference
  • 28. User Defined Functions Call by value example code: Output: Call by reference example code: Output:
  • 30. Pointers What is pointer?  Pointer reduces the code and improves the performance, it is used to retrieving strings, trees etc. and used with arrays, structures and functions.  We can return multiple values from function using pointer.  It makes you able to access any memory location in the computer's memory.
  • 32. Usage of Pointer Dynamic memory allocation  In c language, we can dynamically allocate memory using malloc() and calloc() functions where pointer is used. Arrays, Functions and Structures  Pointers in c language are widely used in arrays, functions and structures. It reduces the code and improves the performance.
  • 33. Declaring a Pointer We use the asterisk (*) symbol to designate a variable as a pointer in C++. The asterisk symbol can be placed anywhere before the pointer name and after the datatype. Syntax : If we have to declare two (or more) pointers together in the same line, we will need to use the asterisk symbol before each variable name. For example:
  • 34. Pointer Example Printing Address & Value of the variable using Pointer Output
  • 35. Pointer Example Program to swap 2 numbers without using 3rd variable Output
  • 36. Double Pointers What is double pointers?  Regular pointer is to refer to an object in memory, then a double pointer is a variable that points to another pointer which in turn, points to an object in memory.  Double pointer is also known as pointer to pointer.
  • 37. Declaring Double Pointers Declaring a Pointer to a Pointer in C++ or double-pointer is very similar to declaring a single pointer; the only difference is that an extra * is added. For Example Syntax :
  • 38. Double Pointers Example The simple working of double pointer Output
  • 39. New & Delete Operator The “new” operator is used to allocate memory for a variable or any other entity like objects or arrays on a heap memory area. If a sufficient amount of memory is available on the heap, the new operator will initialize the memory and return the address of the newly allocated memory and you can use pointers to store the address of that memory location. Output Example Since the programmer has allocated memory at runtime, it’s the responsibility of the programmer to delete that memory when not required. So at any point, when programmers feel a variable that has been dynamically allocated is no anymore required, they can free up the memory that it occupies in the free store or heap with the “delete” operator. It returns the memory to the operating system. This is also known as memory deallocation. Also, memory
  • 40. Class  Description & Structure : A class is a blueprint for the object. We can think of a class as a sketch (prototype) of a house. It contains all the details about the floors, doors, windows, etc. Based on these descriptions we build the house. House is the object.
  • 41. Objects  Description & Structure : When a class is defined, only the specification for the object is defined; no memory or storage is allocated. To use the data and access functions defined in the class, we need to create objects.
  • 42. Class & Objects Sample  Program :