is subscript operator [ ] unary or binary operator ?
I'm quite new to C++ and was going through operator operloading and wondered is subscript a unary or binary?
The subscript operator is a binary operator in the strict sense as it takes two arguments, the reference to the object and the value.
int arr[3];
Here you can see that [] operator makes use of both arr and 3.
According to the C++ Standard
13.5.1 Unary operators
1 A prefix unary operator shall be implemented by a non-static member function (9.3) with no parameters...
and
13.5.2 Binary operators
1 A binary operator shall be implemented either by a non-static member function (9.3) with one parameter...
Thus the subscript operator is a binary operator.
The Unary operators in C++ are:
unary-operator: one of
* & + - ! ~
and also you may add to unary operators
++ cast-expression
-- cast-expression