Why compile error “Use of unassigned local variable”?

前端 未结 10 2210
说谎
说谎 2020-11-22 03:16

My code is the following

int tmpCnt;  
if (name == \"Dude\")  
   tmpCnt++;  

Why is there an error Use of unassigned local variabl

10条回答
  •  故里飘歌
    2020-11-22 03:56

    local variables don't have a default value.

    They have to be definitely assigned before you use them. It reduces the chance of using a variable you think you've given a sensible value to, when actually it's got some default value.

提交回复
热议问题