java - Can't understand purpose of a = b = 0; -


i'm reading java beginners guide , in points of book there piece of code confuses me can't find explanation of does.

int a; int b; = b = 0; //this line don't understand. 

what understand value of 0 copied b , b copied don't understand point of be. example be:

queue(int size) {    char q[];    putloc = getloc = 0; } 

my question is, point of piece of code if you're trying create first in first out queue or line using array?

it's shortcut same this:

a = 0; b = 0; 

why a = b = 0; works? because assignment operation expression associates right left, b = 0 executes first, assigning 0 b , value in b assigned a, this: a = b. being explicit association order, what's happening:

(a = (b = 0));    ^    ^    |    |    |    executes first    executes second 

and why this? well, make explicit both variables have same value (and save few keystrokes), sacrificing readability in process. think it's more clear declare , assign each variable in separate line, if have same initial value:

int = 0; int b = 0; 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -