M
Mike Wahler
qazmlp said:I am sorry for my previous incomplete posting.
Here is the correct one:
size_t len = strlen( myCString ) ;
for( WHAT i = 0 ; i < len ; ++i )
{
// iterate through the string
// and do some operations
}
What is the best choice to replace 'WHAT' in the above code?
size_t or int ? Why ?
If you *know* your indices will *always* fall in the range
of type 'int', then you could use it.
Or if you don't want to be bothered with such annoying
details that could bite you later, use 'size_t' which
is *guaranteed* to be able to represent any index value.
So, neither 'int' nor 'size_t' is necessarily "right" or
"wrong" per se, but if asked for advice, I say use 'size_t'
whenever storing the size of an object or an array index.
-Mike