My code is the following
int tmpCnt;
if (name == \"Dude\")
tmpCnt++;
Why is there an error Use of unassigned local variabl
Local variables are not automatically initialized. That only happens with instance-level variables.
You need to explicitly initialize local variables if you want them to be initialized. In this case, (as the linked documentation explains) either by setting the value of 0 or using the new
operator.
The code you've shown does indeed attempt to use the value of the variable tmpCnt
before it is initialized to anything, and the compiler rightly warns about it.