• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Carey Brown
  • Frits Walraven

=+ operator

Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Mala Gupta's SE 7 book, it said that =+ didn't exist, but I just tested it and it compiled and ran fine.
Is this a typo or something else?
Posts: 23873
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Well, what did you do? Did you do something like this?

If so, then it is *not* an "=+" operator. It is two operators. You are doing an assignment, where the RHS is going through an unary plus operation.

Ranch Hand
Posts: 99
Chrome Java Windows
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Eric,

please don't be confused. There is a difference between a += and =+
The first one is an assignment operator:

The second example means, as Henry says, two operators. An assignment operator = and an unary operator +.
You can rewrite it like this:

so you can omit the + sign and write

The second example makes more sense if you need to write

So you negate the 10 first and assign the result to a;
Create symphonies in seed and soil. For this tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
    Bookmark Topic Watch Topic
  • New Topic