sony
sony

Reputation: 395

Implementation of Assignment operator

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

Answers (2)

Lee Daniel Crocker
Lee Daniel Crocker

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

Vlad from Moscow
Vlad from Moscow

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

Related Questions