Pages: [1]   Go Down
Author Topic: Small mistake in reference about SizeOff  (Read 869 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To whom it may concern:

http://arduino.cc/en/Reference/Sizeof

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
}
Logged

Seattle, WA
Offline Offline
God Member
*****
Karma: 11
Posts: 673
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Pages: [1]   Go Up
Jump to: