File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes C / C++ and the fly likes operators in c Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » C / C++
Bookmark "operators in c" Watch "operators in c" New topic

operators in c

aaka jain

Joined: May 16, 2013
Posts: 12
void main(){
int a;

it is giving me output as 120,as multiplication has higher priority than addition so i think output should be 102,can sonebody please explain me why i m getting output as 120,thanks
Matthew Brown

Joined: Apr 06, 2010
Posts: 4543

Multiplication has higher precedence than addition. But addition has higher precedence than assignment, and *= is considered an assignment operator.
Mike Blaszczak

Joined: Sep 02, 2013
Posts: 25

The combined operators, like += and *=, can always be thought of as treating their right hand operator as a grouped expression. That is, "a *= 10 + 2" is equivalent to "a = a * ( 10 + 2 )", and is not equivalent to "a = a * 10 + 2".

chuck morris

Joined: Oct 18, 2013
Posts: 6
the point is that you should not forget about associative here(association > precedence ( ) ) . X= has right to left association .
I agree. Here's the link:
subject: operators in c
It's not a secret anymore!