user45082: I would like to ask about a weirdness in my program. This is my program:
void setup() {
  Serial.begin(9600);
}

void loop() {
   workout_Text();
}

void workout_Text() {
  int woT_x[] = {1, 4, 8, 12, 16};
  int woT_y[] = {1, 4, 8, 12, 16};
  int n = sizeof(woT_y);
  on_led(woT_x, woT_y, n);
}

void on_led(int a_mat[], int b_mat[], int m) {
  for (int i = 0; i < m; i++) {
    Serial.print(a_mat[i]);
    Serial.print(" : ");
    Serial.println(b_mat[i]);
    delay(100);
  }
} 

This is the part of my program for a LED matrix. The on_led purpose function is for printing the value of a_mat and b_mat. Instead of printing:
1 : 1
4 : 4
8 : 8
12 : 12
16 : 16
1 : 1
4 : 4
8 : 8
16 : 16

It prints:
1 : 1
4 : 4
8 : 8
12 : 12
16 : 16
13312 : 1
23296 : 4
1 : 8
4 : 12
8 : 16
1 : 1
4 : 4
8 : 8

Where does the big number come from? I am sure that my code is right to just print the a_mat and b_mat.
Thank you.

user37622: sizeof counts bytes. the type of your array is int. sizeof of the int array of length 5 is 10 bytes. your for loop goes to i < 10 and reads after the 5th item of the array.

user37857: sizeof() returns the total number of bytes. If you have an array of 5 ints, where each int is 2 bytes long, sizeof will return 10.
If you want the number of elements in the array, you need to divide by the size of a single element:
int n = sizeof(woT_y) / sizeof(woT_y[0]);


45082: <p>I would like to ask about a weirdness in my program. This is my program:</p>

<pre><code>void setup() {
  Serial.begin(9600);
}

void loop() {
   workout_Text();
}

void workout_Text() {
  int woT_x[] = {1, 4, 8, 12, 16};
  int woT_y[] = {1, 4, 8, 12, 16};
  int n = sizeof(woT_y);
  on_led(woT_x, woT_y, n);
}

void on_led(int a_mat[], int b_mat[], int m) {
  for (int i = 0; i &lt; m; i++) {
    Serial.print(a_mat[i]);
    Serial.print(" : ");
    Serial.println(b_mat[i]);
    delay(100);
  }
} 
</code></pre>

<p>This is the part of my program for a LED matrix. The <code>on_led purpose</code> function is for printing the value of <code>a_mat</code> and <code>b_mat</code>. Instead of printing:</p>

<pre><code>1 : 1
4 : 4
8 : 8
12 : 12
16 : 16
1 : 1
4 : 4
8 : 8
16 : 16
</code></pre>

<p>It prints:</p>

<pre><code>1 : 1
4 : 4
8 : 8
12 : 12
16 : 16
13312 : 1
23296 : 4
1 : 8
4 : 12
8 : 16
1 : 1
4 : 4
8 : 8
</code></pre>

<p>Where does the big number come from? I am sure that my code is right to just print the <code>a_mat</code> and <code>b_mat</code>.</p>

<p>Thank you.</p>
 37622: <p><code>sizeof</code> counts bytes. the type of your array is int. sizeof of the int array of length 5 is 10 bytes. your <code>for</code> loop goes to i &lt; 10 and reads after the 5th item of the array.</p>
 37857: <p><code>sizeof()</code> returns the total number of bytes. If you have an array of 5 ints, where each int is 2 bytes long, sizeof will return 10.</p>

<p>If you want the number of elements in the array, you need to divide by the size of a single element:</p>

<pre><code>int n = sizeof(woT_y) / sizeof(woT_y[0]);
</code></pre>
