This week's book giveaway is in the Go forum.
We're giving away four copies of Head First Go and have Jay McGavren on-line!
See this thread for details.
Win a copy of Head First Go this week in the Go forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Chapter 2 CASE statement topic question (pg 73 )  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I was working on review question 20 and came across this scenario.
According to the book, " the values in each case statement must be compile-time constant values of the same data type as the switch value" .
Though the switch value type is 'char' and the statement  'case 1' below has value type of int, the program is compiling without any errors. I was expecting it to give a compile error when it encounters case 1.  
What am i missing?  TIA !

 
Rancher
Posts: 802
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


In your code and my code, the 1 is autoboxed as a char corresponding to the nonprintable char with numeric value of 1, not '1'. When it is cast back, you can see the value has not changed.
 
Marshal
Posts: 63485
207
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't try coloured text or bod print inside code tags; as you have seen, it doesn't work. I have deleted the tags.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!