Use of unassigned local variable that is assigned

后端 未结 3 2045
囚心锁ツ
囚心锁ツ 2021-01-23 12:39

The below code runs a \'for\' loop to create months 1 through 12 then names each month Jan through Dec according to their number. That pieces compiles fine. At the bottom wher

3条回答
  •  情话喂你
    2021-01-23 12:54

    You will be surely declaring monthName outside scope also(in your loop it declared again). other wise the program should tell compile error. right click on the variable then "Go to defenision". If so variables are different. so only its misbehaving

    The reason is two variables having different memory in primary memory. so one memory update won't effect the other. Compiler will use maximum local variable for its processing. Inside loop its the declared one inside. Outside the loop its the outside one

    So if you needn't the outer variable value further don't declare it again inside. other wise you declare it outside of the loop with some other name

提交回复
热议问题