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
………………
………………
{
x=90;
……..
……..
}
………
………
{
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
<iostream>
using namespace std;
n=15;
main()
{
n=10;
{
k=n;
n=50;
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";
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