File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Languages » C / C++
Bookmark "operators in c" Watch "operators in c" New topic
Author

operators in c

aaka jain
Greenhorn

Joined: May 16, 2013
Posts: 12
void main(){
int a;
a=10;
a*=10+2;
printf("%d",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
Bartender

Joined: Apr 06, 2010
Posts: 4344
    
    8

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

Joined: Sep 02, 2013
Posts: 22

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
Greenhorn

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: http://aspose.com/file-tools
 
subject: operators in c
 
Similar Threads
Hibernate Query taking long time
OPERATOR'S
Dave Allen's notes is great
variable declaration changes output
Protected variables ONLY viewable to sub classes