• Post Reply Bookmark Topic Watch Topic
  • New Topic

declaration(?)  RSS feed

 
Philip Freeman
Ranch Hand
Posts: 31
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why does this not pop an error: int x, y = 0, i;
like int x = 0;
int y = i; (The local variable may or may not have been initialized)
aren't i assigning i to y? and i is not previously initialized or declared, but it does not pop an error in first case?


 
Paweł Baczyński
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Philip Freeman wrote:aren't i assigning i to y?

You are not assigning i to y. You are declaring variable i without giving it a value.

This code:
int x, y = 0, i;

and this code:
int x;
int y = 0;
int i;


both mean the same.
 
Campbell Ritchie
Marshal
Posts: 56595
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paweł Baczyński wrote: . . .
both mean the same.
There is a big difference, however. You can read the second version.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!