• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Pre increment of byte and short variables

 
Ranch Hand
Posts: 205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Can any of you find any bug in below program -
1. byte b=1;
2. ++b;
3. System.out.println(b);
I am getting the output as - 2.
Is ++b means, b=b+1;
Here right hand value is int how is it possible to assign to byte variable.
Is ++b means, b==(b)(b+1)?
I thought it is only for assignment operators, i.e
b+=1 --> b=(b)(b+1)
Please clarify my doubt..
Thanks..
 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
byte b = 1;
b++;
or
++b;
means
b = (byte) (b + 1);
 
reply
    Bookmark Topic Watch Topic
  • New Topic