Your SlideShare is downloading. ×
C++ Session 3
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

C++ Session 3

817
views

Published on


0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
817
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
42
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Session 3
  • 2. Session objectives (1)
      • Identify operators
      • Assignment
      • Arithmetic
      • Compound
      • Assignment
      • Relational
      • Logical
      • Bitwise
      • Understand precedence and evaluation
    • of operators
  • 3.
      • Discuss mixed mode expressions
    • and implicit type conversions
      • Understand type casting
    • and type compatibility
      • Identify C++ shorthand operators
    Session objectives (2)
  • 4. Introduction Operators are:
      • Are a set of characters
      • Have specific meaning particular to a language
      • Do not include special characters
    • ; “ : ,
  • 5. Operands
  • 6. Binary Arithmetic Operators (1) Require two operands
  • 7. Binary Arithmetic Operators (2) Adds the values of operands result = The addition operator
  • 8. Binary Arithmetic Operators (3) Subtracts the second operand from first answer = The subtraction operator
  • 9. Multiplies the operands ans = The multiplication operator Binary Arithmetic Operators (4)
  • 10. Divides the first operand by the second The division operator result = Binary Arithmetic Operators (5)
  • 11. Store the remainder after integer division The modulus operator answer = Binary Arithmetic Operators (6)
  • 12. void main(void) { : cout << endl ; f_dist = f_speed * f_time ; cout<<&quot;The distance covered by the vehicle = &quot; ; cout<< f_dist ; cout << endl ; } Multiplication operator Binary Arithmetic Operators (7)
  • 13. Unary arithmetic operators (1) Require one operand
      • Negation operator -
      • Increment operator ++
      • Decrement operator - -
    int x; int x= -3 stnd ++ OR ++stnd puls - - OR - - puls
  • 14. #include <iostream.h>   void main(void) { int value ; value = 1 ;   cout << &quot;THE INCREMENT OPERATOR&quot; << endl ; cout << &quot;Value of value: &quot; << value << endl ; cout << &quot;Pre-fix increment operator (++value): &quot; << ++value ; cout << endl ; cout << &quot;Value of value: &quot; << value << endl ; cout << &quot;Post-fix increment operator (value++): &quot; << value++ ; cout << endl ; cout << &quot;Value of value: &quot; << value << endl ;   Unary arithmetic operators (2)
  • 15. cout << &quot; THE DECREMENT OPERATOR&quot; << endl ; cout << &quot;Value of value: &quot; << value << endl ; cout << &quot;Pre-fix decrement operator (--value): &quot; << --value ; cout << endl ; cout << &quot;Value of value: &quot; << value << endl ; cout << &quot;Post-fix decrement operator (value--): &quot; << value-- ; cout << endl ; cout << &quot;Value of value: &quot; << value << endl ; } Unary arithmetic operators (3)
  • 16. Assignment operator Assignment operator
  • 17. Multiple assignment int var_1, var_2, var_3 ; var_1 = 70 ; var_2 = 70 ; var_3 = 70 ; var_1 = var_2 = var_3 = 70 ; int var_1 = int var_2 = int var_3 ;
  • 18. Relational operators (1) - Comparative action on data - test relationship between variables
  • 19. Relational operators (2) == Equal to > Greater than < Less than != Not equal to >= Greater than or equal to <= Less than or equal to
  • 20. Relational operators (3) b == 3 b== c Equal to Greater than b > 3 b > c Less than b < 3 b < c Less than Equal to b <= 3 b <= c Greater than Equal to b >= 3 b>= c Not equal to b!= 3 b!= c
  • 21. Logical operators (1)
  • 22. Logical operators (2) qual == 12 && age == 18 qual == 10 || age == 18 ( ! ( age >= 18) )
  • 23. Precedence and Order of Evaluation
  • 24. Mixed mode Expressions & Implicit Type conversion X = 5 * 6.7 ; integer float No error Integer converted to double automatically
  • 25. Conversion table
  • 26. Type conversion (1) Floating point variables Integer values Value is not changed
  • 27. Type conversion (2) Floating point variables Integer values Value is changed
  • 28. Adding integers to characters
  • 29. Type casting (1) Use explicit type conversions in mixed mode expressions float a ; (int) a ; Often leads to
  • 30. Type casting (2) float a =10.0, b = 3.0, c ; c = a / b ; Ans= 3.333333 c = (int) a / (int) b OR c = (int) ( a / b ) Ans= 3
  • 31. C++ Shorthand Operators (1) Help in reducing the code required in programming constructs test_val = test_val + 5; test_val += 5;
  • 32. C++ Shorthand Operators (2) Every shorthand operator consists of An arithmetic operator +, -, /, *, %
  • 33. C++ Shorthand Operators (3)