Can anyone explain this code to me?

Can anyone explain this code to me ----- a+=(a==number) ?

  • Thank you in advance.

  • Answer:

    It is possibly python, maybe c because python has taken a lot from c. It is basically trying to make a=a+boolean(True or false value). a==number, returns a boolean. The word "number" in this code is a variable. So basically when they write == you are asking the computer if the two are the same. If a is the same as number it will return true, if not it will return false. += means that a becomes a+ what ever you put on the other side of the =.

Princess Jamela at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

in C there are arithmetic operators and comparison operator. += is an arithmetic operator, x+=5 is the same as x= x+5, this is a legal statement because x+5 is evaluated first, then x+5 is reassigned to x, so if x is 6, x = x+5 will assign the value 11 to x. == is a comparison operator, comparison operators result in a value of 1 if the comparison succeeds or result in the value 0 if the comparison fails, but this result is not usually assigned this way by convention, but C allows it. You would normaly only store a success or failure in a seperate int or boolean variable or maybe even keep track of the number of successes or failures, but the convoluted expression in your example seems to have no purpose. your example of a+=(a==number) is just nerd geek stuff

If a equals number, a is assigned the value of a + 1 (increments the value of a with 1) It not, a is assigned the value of a + 0 (a remains the same value). It could be written like: a = a + (a == number); or even: if (a == number) a = a + 1; // alternatively a += 1 or a++; The latter is the least confusing perhaps. Another alternative could be to use a ternary a = a + (a == number ? 1 : 0);

If this is C or C++ than you are adding 1 to a assuming that a is equal to number and 0 if it's unequal. If this is Java than you're just going to get an error.

It could be written like: a = a + (a==number); reassigning the value of a

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.