operators in c++

operators in c++

c++ has a rich set of operators. All c operators are valid in c++ also, In additional , in the c++ language introduces some new operators. we have already seen two such operators, namely, the insertion operator << , and the extraction operator >> other new operators are given below

:: scope resolution operator
->* pointer to member operator
::* pointer to member declarator
.* pointer to member operator
delete memory release operator
end1 line feed operator
new memory allocation operator
setw field width operator

Scope resolution operator

like C and c++ is also a block structure language. block and scopes can be used in constructing programs.we know that the same variable name can be used to have different meanings in different blocks. The scope of the variables extends from the point of its declaration till the end of the block that containing the declaration. A variable declared inside a block is said to be local to that block. consider the following segment of a programs

………………
………………
{
int x=90;
……..
……..
}
………
………
{
int x=100;
………
………
}

the two declaration of c refer to two different memory locations containing different values. statements in the second block can’t refer to the x variable declared in the first block, and vice versa. blocks in c++ are often nested. for example the following style is common

c plus plus block scopes picture

#include<iostream>
using namespace std;
int n=15; //global variable n
int main()
{
int n=10; // n redeclare local to main
{
int k=n;
int n=50; // n declare again to local inner block
std::cout<<"this is inner block \n";
std::cout<<"k="<<"n="<<"::n="<<::n<<"\n"; }
std::cout<<"\n this is outer block \n";
std::cout<<"n="<<"::n="<<::n<<"\n";
return 0;
}

output:
this is inner block
k=10
n=50
::n=15
this is outer block
m=10
::m=15

in the above example the variable n is declared at three places , namely, outside the main() function, inside the main(), and inside the inner block

Note: it is to be noted ::n will allows refer to the global n. in the inner block , ::n refers to the values 10 and 15

MEMBER DEREFERENCING OPERATORS

as we know c++ permits us to define a class containing various types of data and functions as members, c++ also permits us to access the class members through pointers. In order to achieve this c++ provides a set of three pointer-to-member operators , in the table show those operators and their functions further details on these operators will be meaningful only after we discuss classes, and therefore we defer the use of member dereferencing operators until then

member dereferencing operator in c plus plus picture

  • C++ Dynamic Initialization of Objects
  • C++ Copy Constructor
  • C++ Dynamic Constructor
  • C++ Destructors
  • C++ Exercise
  • C++ Operator Overloading
  • C++ Overloading Unary Operators
  • Const pointer in C
  • Void pointer in c
  • C++ Overloading Binary Operators
  • C++ Overloading Binary Operators Using Friends
  • C++ Manipulation String Using Operators
  • C++ Rules for overloading operators
  • C++ Exercise
  • C++ Basic To class Type
  • C++ Class TO Basic Type
  • C++ One class To another class type
  • C++ Exercise
  • C++ Inheritance introduction
  • C++ Single Inheritance
  • C++ Multiple Inheritance
  • C++ Ambiguity Resolution in inheritance
  • C++ Hierarchical Inheritance
  • C++ Hybrid Inheritance
  • C++ Virtual Base Classes
  • C++ Exercise
  • C++ abstract class
  • C++ nesting of classes
  • C++ Exercise
  • C++ polymorphism
  • C++ Exercise
  • C++ pointers
  • C++ Pointers TO object
  • C++ this pointer
  • C++ Pointer to Derived class
  • C++ Virtual functions
  • C++ Exercise
  • C++ streams
  • C++ unformatted I/O operations
  • C++ Put() and get()
  • C++ getline() and write()
  • C++ Formatted console I/O
  • C++ Manipulators
  • C++ Exercise
  • C++ file handling
  • C++ file stream classes
  • C++ Open and closing file
  • C++ open using constructor
  • C++ open using open()
  • C++ Detecting End of file
  • C++ File modes
  • C++ File pointers and Manipulators
  • C++ Sequential I/O
  • C++ Reading and Writing
  • C++ Updating a File
  • C++ Error handling In File
  • C++ Command Line Arguments
  • C++ Exercise
  • C++ Template introduction
  • C++ Class Templates with multiple Parameters
  • C++ Function templates
  • C++ Function templates with multiple parameters
  • C++ member function Template
  • C++ Exercise
  • C++ Exception handling
  • C++ Basics of Exception Handling
  • C++ Exception Handling Mechanism
  • C++ Throwing Mechanism
  • C++ Catch Mechanism
  • C++ Catch all Exceptions
  • C++ Re-Throwing An Exception
  • C++ Specifying Exceptions
  • C++ Exercise