Reputation: 1
I know it returns whatever is on left side. So in case of character assignment we would get a character and in case of int assignment we would get a int type.
Isn't there a fix datatype of assignment operator?
Upvotes: 0
Views: 232
Reputation: 145269
In C++:
The built-in assignment operator returns a reference, or more precisely, an assignment expression is an lvalue.
Returning a reference is also required for an item in a standard collection.
Apart from that you can define an assignment operator for a class type, with any return type you want, including void
(which otherwise IMHO would have been preferable).
In C:
In C there are no user defined assignment operators, and an assignment expression is an rvalue. I.e., in C you can't do (a = b) = c
that you can do in C++. Which IMHO is an advantage.
Upvotes: 2
Reputation: 134326
Quoting C11
, chapter §6.5.16, Assignment operators (emphasis mine)
[...] An assignment expression has the value of the left operand after the assignment, but is not an lvalue. The type of an assignment expression is the type the left operand would have after lvalue conversion.
Upvotes: 2