objective c - What is the default value of an NSUInteger in local scope? -
this question has answer here:
- are ints initialized 0? 3 answers
given following snippet:
- (void)dosomething { nsuinteger count; }
what count? guaranteed 0?
no, isn't guaranteed zero, since it's local automatic variable. without initialization, value indeterminate. if want zero, either initialize it:
nsuinteger count = 0;
or define static
:
static nsuinteger count;
since variables static storage duration implicitly intialized zero, note has side effects (namely value persists between function calls).
Comments
Post a Comment