I'm initializing my array to a size of 3 and then assigning 5 elements in it.
uint8_t test[3] = {};
for (i = 0; i <= 5; i++)
{
test[i]= i;
}
I'm initializing my array to a size of 3 and then assigning 5 elements in it.
uint8_t test[3] = {};
for (i = 0; i <= 5; i++)
{
test[i]= i;
}
Because C doesn't work that way. As the programmer, you are responsible for making sure the array indexes do not go out of bounds.
One way to get around this is, if you know how long your array needs to be, create a variable and use it in your program like so:
const int ARRAY_LENGTH = 3;
uint8_t test[ARRAY_LENGTH];
for (int i = 0; i < ARRAY_LENGTH; i++)
{
test[i] = i;
}
That way, if the array length needs to change, you only need to remember to change it in one place instead of every where it is used.