Note details

Arithmetic Operators in C++

BY lx8iq
August 23, 2025
Public
Private
9803 views

Lecture Overview: Operators in C++

Welcome to Nesso Academy's Chapter 3, focusing on operators in C++. This chapter will cover various types of operators, specifically starting with arithmetic operators.

Topics Covered

  1. Introduction to Arithmetic Operators

    • Purpose: Perform basic mathematical operations such as addition, subtraction, multiplication, and division.
    • Applicable Numeric Types: Works primarily with int, float, and double.
  2. Unary Arithmetic Operators

    • Definition: Operators that require one operand.
    • Types:
      • Unary Plus: Does not affect the numeric value.
      • Unary Minus: Changes the sign of the numeric value.
    • Examples:
      int val = -4;
      cout << +val; // Output: -4
      cout << -val; // Output: 4
      
    • Recommendation: Avoid using unary plus as it is not impactful.
  3. Binary Arithmetic Operators

    • Definition: Operators that operate on two operands.
    • List of Operations and Examples:
      • Addition (+): 10 + 3 results in 13.
      • Subtraction (-): 10 - 3 results in 7.
      • Multiplication (*): 10 * 3 results in 30.
      • Division (/): 10 / 3 results in 3 (integer division).
      • Modulus (%): 10 % 3 results in 1.
  4. Important Points about Arithmetic Operators

    • Floating Point Division: Result is floating point if either operand is floating point:
      12 / 5.0 // Output: 2.4
      
    • Integer Division: Result is integer if both operands are integers:
      12 / 5 // Output: 2
      
    • Division by Zero: Causes runtime error.
    • Division by 0.0: May result in INF (infinity) or NaN (not a number), depending on system representation (IEEE 754).

This concludes the lecture on arithmetic operators in C++. Thank you for attending, and see you in the next session!