C++Introduction to C++Learn C++

Learn How To Use Operators In C++

C Programming language is one of the oldest programming language. A lot of operands in other programming languages got inspiration from this language. C and C++ have the same operators and most of them are the same in other programming languages.

In programming variable at the left side of the equation symbol is a new variable, or variable that will have new value from the right side of the equation. And the variables at the right side are current variables with their values. For example, you can define a as an integer variable to a result of 2+3,

this is same with

For a beginner, or someone (i.e. mathematician) who doesn’t know programming language equations and operators might seem to be weird. For example, let’s look at this simple equation.

Here, the equation at the second line, might be weird to a beginner because in mathematics it is something like,

As you see, in programming, using mathematical operations in programming is different than mathematical science. In scientific researches, in some cases, in these operations (mostly on floating point numbers) you must verify computational operations done with real mathematics, or you should understand well the mechanics of programming .

In programming , basically we can group these ways to use operators, Arithmetic Operators, Assignment Operators, Comparison Operators and Logical Operators.

1. Arithmetic Operators

Basic Arithmetic Operator are;

Addition (+) : Adds two values, here are two different examples with integer and floating point numbers

Subtraction (-) : Subtracts one value from another

Multiplication ( * ) : Multiplies two values x * y

Division ( / ) : Divides one value by another

Modulus ( / ): Returns the division remainder

Increment (++): Increases the value of a variable by 1

Decrement (–): Decreases the value of a variable by 1

2. Assignment Operators

Basic assignment operator are the same as arithmetic’s, as they are used to assign values to variables, by using with = equation symbol. Assignment Operators are listed below with examples;

Equation ( = ) : Assigns lefts side variable to the result of right side,

Addition Assignment ( += ) : Adds result of right side to the left side variable,

Subtraction Assignment ( -= ) : Subtracts result of right side from the left side variable,

Multiplication Assignment ( *= ) : Multiplies variable left side with the right side ;

Division Assignment ( /= ) : Multiplies variable left side to the result of the right side;

Power Assignment ( ^= ) : Power of variable;

Modulus Assignment ( %= ) : Results modulus of variables;

Logical AND Assignment ( &= )

Logical OR Assignment ( |= )

Shifting Bits to Left Assignment ( >>= )

Shifting Bits to Right Assignment ( <<= )

3. Comparison Operators

All comparison operators are given in this example below,

4. Logical Operators

In C & C++ programming language,
&& is used as AND,
|| is used as OR,
! symbol is used as NOT.

Logical operators are given below,

 

close

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.

About author

33+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux and some other operating systems. Dr. Yilmaz Yoru was born in 1974, Eskisehir-Turkey. He graduated from the department of Mechanical Engineering of Eskisehir Osmangazi University in 1997. One year later he started to work in the same university as an assistant. He received his MSc and PhD degrees from the same department of the same university. He has married and he is a father of a son. Some of his interests are Programming, Thermodynamics, Fluid Mechanics and Artificial Intelligence. He also likes the graphical 2D & 3D design and high-end innovations.
Related posts
C++C++11C++14C++17Introduction to C++Learn C++

This Is How To Get A Substring of a Wide String in C++

C++C++11C++14C++17Introduction to C++Learn C++

How To Access Individual Character Elements Of A C++ String

C++C++11C++14C++17Introduction to C++Learn C++

The Right Way To Access Character Elements Of A Wide String

C++Language FeatureLearn C++

You NEED to Learn To Use JSON (JavaScript Object Notation)

en_USEnglish