Skip to main content
Engineering LibreTexts

5.4: Arithmetic Assignment Operators

  • Page ID
    10264
  • Overview of Arithmetic Assignment

    The five arithmetic assignment operators are a form of short hand. Various textbooks call them "compound assignment operators" or "combined assignment operators". Their usage can be explaned in terms of the assignment operator and the arithmetic operators. In the table we will use the variable age and you can assume that it is of integer data type.

    Arithmetic Assignment Examples: Equivalent Code:
    age += 14; age = age + 14;
    age -= 14; age = age - 14;
    age *= 14; age = age * 14;
    age /= 14; age = age / 14;
    age %= 14; age = age % 14;

    Demonstration Program in C++    

    Creating a Folder of Sub-Folder for Source Code Files

    Depending on your compiler/IDE, you should decide where to download and store source code files for processing. Prudence dictates that you create these folders as needed prior to downloading source code files. A suggested sub-folder for the Bloodshed Dev-C++ 5 compiler/IDE might be named:

    • Demo_Programs

    If you have not done so, please create the folder(s) and/or sub-folder(s) as appropriate.

    Download the Demo Program

    Download and store the following file(s) to your storage device in the appropriate folder(s). Following the methods of your compiler/IDE, compile and run the program(s). Study the soruce code file(s) in conjunction with other learning materials.

    Download from Connexions: Demo_Arithmetic_Assignment.cpp