TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

C++

C++ Arithmetic Operators

Overview

In this tutorial, we will learn about C++ Arithmetic Operators with a sample program. Arithmetic operators are used to performing arithmetic calculations.

C++ Arithmetic Operators

 

Operation Operator Description Sample Example
Addition + Adds the two operands sum = a + b
Subtraction – Subtracts the second operand from the first operand diff = a – b
Multiplication * Multiplies the two operands product = a * b
Division / Divides the numerator by the denominator div = a/b
Modulus % The remainder of the integer division a%b
Increment ++ Increments the value of the operand by 1 i++
Decrement — Decrements the value of the operand by 1 j–

 

C++ Program

/************************************
* C++ Arithmetic Operators
* Filename: arithmetic.cpp
* C++ Arithmetic Operators Demo
* program.
* C++ Tutorials - www.TestingDocs.com
**************************************/
#include
using namespace std;
int main()
{
 //Declare two variables
 int a=20,b=5;
 //Used in Arithmetic calculations
 double product,div,rem;
 int sum,difference;
 //Perform Arithmetic calculations
 sum = a + b; // addition
 difference = a - b; // subtraction
 product = a*b; // product
 div = a/b; // divide
 rem = a%b; // get remainder
 // Print Statements
 cout << "Sum = " << sum << endl;
 cout << "Difference = " << difference << endl;
 cout << "Product = " << product << endl;
 cout << "Division = " << div << endl;
 cout << "Modulus = " << rem << endl;
 cout << "Increment = " << ++a << endl; //pre-increment
 cout << "Decrement = " << --b << endl; //pre-decrement
 return 0;
} // end main

C++ Arithmetic Operators

That’s it. Analyze the program output and understand how the operators work.

—

C++ Tutorials

C++ Tutorials on this website:

https://www.testingdocs.com/c-coding-tutorials/

For more information on the current ISO C++ standard

https://isocpp.org/std/the-standard

Related Posts

g not found OpenSuse

C++ /

Install GCC C++ Compiler on OpenSuse

sum of digits c program

C++ /

Sum of Digits of a Number C++ Program

C++ Hello World Program

C++ /

C++ Hello World Program

C++ /

Object-Oriented Programming Language Examples

C++ /

Object-Oriented Programming Features

‹ C++ Variable Declaration› C++ Relational Operators

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version