Special Operators in C++
C++ language supports some special operators such as comma
operator, sizeof operator, pointer operators (& and *), and member
selection operators (. and ->). pointer
operators will be discussed while introducing pointers and member selection
operators will be discussed with structures and union. Right now, we will
discuss comma operator and sizeof operator.
(a) Comma Operator
This operator is used to link
the related expressions together.
Example: int val, x, y;
value = (x = 0, y = 5,
x+y);
It first assigns 10 to x, then 5
to y, finally sum x+y to val.
(b) (b) sizeof Operator
The sizeof operator is a compile
time operator and when used with an operand, it returns the number of bytes the
operand occupies. The operand may be a variable, a constant or a data type
qualifier.
Example: int n;
n = sizeof (int);
cout<<n;
output: n = 2 /*
Assuming that int size is 2 bytes */
No comments:
Post a Comment