Operators

Operators are tokens that perform some computation when applied to variables and other objects in an expression. they can be unary or binary.

Unary Operators

Unary operators require one operator to operate upon. The following are examples of unary operators.

& Address operator

* Indirection operator

+ Unary plus

- Unary minus

~ Bitwise operator

++ increment operator

-- decrement operator

! Logical NOT

Binary Operators

Binary operators require two operands to operate upon.

Ternary Operators

Such operators require three operands. One example is the Conditional operator ? :

Variables

A variable in a programming language is a symbolic name for a computer memory location. In other words, a variable in a program is a name(symbol) we give to a memory location that will hold some piece of information useful in the program.

Initialization of variables

Defining a variable does not assign an initial value to the variable. When a variable is declared e.g.

int P;

a storage location is occupied in the memory. And after initializing the variable

int P = 100;

that storage location will hold the value 100.

Dynamic Initialization

In C++, a variable can be intialized at run-time. This is knownas dynamic initialization. A variable can be initialized at run-time using expressions at the place of declaration. For e.g.

float average;

average = total / num;

These two statements can be combined into one as:

float average = total / num

HOME LEARN C++ PREVIOUS NEXT