Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About switch...

 
Rashmi Tambe
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at following code...

at line marked as 1 , compiler complains as
variable k might not have been initialised
I don't understand why?? if k is not visible to case 3 block , it should have given the error...
variable k undefined.
And if it is visible (in scope on case 3 block) then k is initialised , then why the the copiler complains...
thanx in advance.
Rashmi
 
ersin eser
Ranch Hand
Posts: 1072
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
k would be initialized only the switch statement hits the case2 and k is a local variable so it does not get initialized auto.
------------------
Have a nice day, Unless you've made other plans.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic