Un3qual Un3qual - 1 year ago 80
Java Question

Declaring multiple variables on one line out of order

I recently saw this in some Java code:

int pos = -1, ch;

Is that the same as

int pos, ch = -1;


Answer Source

No, the first code snippet only initializes pos with -1 and leaves ch uninitialized. The second one does it the other way round leaving pos uninitialized and ch with the value -1. But in either case, both ch and pos will be created and you will be able to set or update their values.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download