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

    • ChatGPT Plans Free and PlusChatGPT Subscription Plans
    • Stellar Converter for Database ToolStellar Converter for Database
    • Stellar MySQL Log AnalyzerStellar Log Analyzer for MySQL
    • Stellar Repair for MySQLStellar Repair for MySQL
    • ChatGPT IntroductionChatGPT Capabilities
    • How to secure your SQL Database: Tips and Tricks
    • ChatGPT4 Conversational AI FeaturesChatGPT4 Conversational AI Features
    • Trends in Software EngineeringShaping the Future of Development: Exploring Key Trends in Software Engineering
    • Java PerformanceImproving Java Performance with Multithreading
    • QDrant Vector DatabaseOpen-source Vector Databases
    • Difference between PHP and JavaScript?
    • Bing AI Browser Web ContentBing Conversation Styles
    • ChatGPT PreviewChatGPT Introduction
    • Open Source AI Frameworks TensorFlowOpen Source AI Frameworks
    • Artificial Intelligence Tools

    Back to Top

    Links

    • Contact
    • Privacy Policy
    • Cookie Policy

    www.TestingDocs.com