Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

conversion question

 
Serge Batov
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I do not understand that this following code compiles just fine

char c = 5;
int i = 10;
c +=i;
But this
char c = 5;
int i = 10;
c = c + i;
give a compile error: possible loss of precision...
What's a difference between those two assignments?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See here. A compound assignment operator like += includes an implied cast, which is missing in your second example.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Serge,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knew I was forgetting something...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic