Skip to content

Commit 7a1a80b

Browse files
authored
Merge PR #538 "Improve sizeof example code" from per1234
Improve sizeof example code
2 parents 15e183f + d139487 commit 7a1a80b

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Language/Variables/Utilities/sizeof.adoc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,15 @@ void loop() {
6666

6767
[float]
6868
=== Notes and Warnings
69-
Note that `sizeof` returns the total number of bytes. So for larger variable types such as ints, the for loop would look something like this.
69+
Note that `sizeof` returns the total number of bytes. So for arrays of larger variable types such as ints, the for loop would look something like this.
7070

7171
[source,arduino]
7272
----
73-
for (i = 0; i < (sizeof(myInts)/sizeof(myInts[0])); i++) {
74-
// do something with myInts[i]
73+
int myValues[] = {123, 456, 789};
74+
75+
// this for loop works correctly with an array of any type or size
76+
for (i = 0; i < (sizeof(myValues)/sizeof(myValues[0])); i++) {
77+
// do something with myValues[i]
7578
}
7679
----
7780

0 commit comments

Comments
 (0)