• Home
  • 3.1 Addition Operator (+)

3.1 Addition Operator (+)

View Categories

3.1 Addition Operator (+)

1 min read

Table of Contents

The addition operator (+) performs arithmetic addition on two operands and produces their sum. It is one of the fundamental arithmetic operators in C++ and is supported for all built-in numeric data types, including integers and floating-point values.

When both operands are integers, the result is an integer. If one or both operands are floating-point values, the operands undergo the usual arithmetic conversions, and the result is a floating-point value.

Source Code #

#include <iostream>

int main()
{
    int num1 = 25;
    int num2 = 15;

    int sum = num1 + num2;

    std::cout << "First Number : " << num1 << '\n';
    std::cout << "Second Number: " << num2 << '\n';
    std::cout << "Sum          : " << sum << '\n';

    return 0;
}

Output #

First Number : 25
Second Number: 15
Sum          : 40

Explanation #

  • The addition operator (+) adds the values of two operands.
  • num1 + num2 evaluates to the sum of the two integer values.
  • The resulting value is assigned to the variable sum.
  • Both operands are of type int, so the result is also an integer.
  • The value stored in sum is displayed using std::cout.
  • The addition operator can also be used with floating-point data types.
  • return 0; terminates the program successfully.

Powered by BetterDocs

Leave a Reply

Your email address will not be published. Required fields are marked *