Go Down

Topic: Small mistake in reference about SizeOff (Read 952 times) previous topic - next topic


To whom it may concern:


the last example:

for (i = 0; i < (sizeof(myInts)/sizeof(int)) - 1; i++) {
  // do something with myInts

will never use the last elem of myInts

should be:

for (i = 0; i < (sizeof(myInts)/sizeof(int)); i++) {
  // do something with myInts


Although in the case of processing strings (as used on that page), skipping the final entry is usually preferred because it's a 0.  That said, the example could definitely be tweaked to be more informative to a beginner by NOT using a string in the example.

Go Up