3 types of special operators in C++
These operators have special purpose in C++.
Special operators in C++ are :
– sizeof()
– Comma (,)
– Scope resolution operator (::)
i. sizeof() in C++
sizeof() finds the size of a data type or value in term of bytes.
//Program to demonstrate the use of sizeof() operator
#include<iostream> using namespace std; int main() { int inum; float fnum; char ch; cout<<"\nsize of int value"<<sizeof(inum); cout<<"\nsize of float value="<<sizeof(fnum); cout<<"\nsize of char value="<<sizeof(ch); cout<<"\nsize of short data type="<<sizeof(short); cout<<"\nsize of double data type="<<sizeof(double); return 0; }
Output
size of int value=4 size of float value=4 size of char value=1 size of short data type=2 size of double data type=8
ii. Comma operator in C++
This operator can separate variables in variable declaration statement and or multiple expressions in same line. It can also be used in functions like round() and strcat() to specify arguments.
//Program to demonstrate the use of Comma operator
#include<iostream> using namespace std; int main() { int a,b,c; c=(a=10,b=3,a-b); cout<<endl<<"a="<<a; cout<<endl<<"b="<<b; cout<<endl<<"c="<<c; return 0; }
Output:
a=10 b=3 c=7
iii .Scope Resolution operator in C++
Click here to know about scope resolution operator