• Home
  • 3.3 Multiplication Operator (*)

3.3 Multiplication Operator (*)

View Categories

3.3 Multiplication Operator (*)

< 1 min read

Table of Contents

The multiplication operator (*) multiplies two operands and returns their product. It 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 = 12;
    int num2 = 8;

    int product = num1 * num2;

    std::cout << "First Number : " << num1 << '\n';
    std::cout << "Second Number: " << num2 << '\n';
    std::cout << "Product      : " << product << '\n';

    return 0;
}

Output #

First Number : 12
Second Number: 8
Product      : 96

Explanation #

  • The multiplication operator (*) multiplies the values of two operands.
  • num1 * num2 evaluates to the product of the two integer values.
  • The resulting value is assigned to the variable product.
  • Both operands are of type int, so the result is also an integer.
  • The value stored in product is displayed using std::cout.
  • The multiplication 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 *