Reputation: 395
Can i write assignment operator in a cascaded manner.Following are two statements how can i write them
total_marks/=1000;
total_marks*=100;
Can we do something like but where we place 100
total_marks*=total_marks/=1000;
Upvotes: 2
Views: 56
Reputation: 13196
No. The result of a /=
or *=
operator will not return an lvalue, and therefore cannot be used to the left of another assignment. What's wrong with the simple, obvious, readable:
total_marks = (total_marks / 1000) * 100;
Upvotes: 4
Reputation: 311186
In C++ you could write for example
( total_marks/=1000 ) *= 100;
However in C this code will not compile.
In C ( and C++ ) you could write the following way using the comma operator
total_marks/=1000, total_marks *= 100;
I mean if you need this in expressions.
Upvotes: 1