C++ Operators

C++ Operators perform operations by taking one or more values, to give another value. These operations are performed on variables and values.

For example a + b, a – b, etc.

Scope Resolution Operator ::

Use this operator, if you want to access the global version of a variable. The global version remains the same throughout the program and the value remains the same even accessed from the inner block.

Here’s an example to easily understand the usage of the scope resolution operator,

On using the scope resolution operator, the global version of the variable “a” can be accessed i.e. a = 10

Here’s the output,

Note: Learn how to create a program and run it in Tubo C++

Scope Resolution Operator C++ Output

Memory Management Operators

Operators for managing memory in C++ include new() and delete(). These operators allocate and free the memory. The new() operator can also create an object. If you want to destroy an object, you can easily do it with delete().

new operator

Use the new operator to create objects of any type in C++. An object declared using new is alive till it is destroyed using the delete operator. The new operator can be overloaded.

Here’s how to declare,

Here’s how you can initialize memory,

The new operator can be used with array to create a memory space. Let’s see how,

delete operator

The delete operator is used to destroy objects created with the new operator,

Here’s how to declare,

The delete operator can be overloaded like the new operator.

Type Cast Operator

Explicit type conversion is possible with the typecast operator.

Here’s the syntax,learn h

Here’s an example,

Memory Dereferencing Operators

The major difference between C and C++ is that C++ has classes. C++ allows defining a class that consists of data and members. So, in C++ you can also access the members through pointers, using the member dereferencing operators.

::*   Declare a pointer to a member of a class

*    Accessing a member using an object name and a pointer to that member.

->*  Accessing a member using a pointer to the object and a pointer to that member.

C++ Data Types
C++ Decision Making Statements
Studyopedia Editorial Staff
Studyopedia Editorial Staff
[email protected]

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading