Why does conn[0][1]
outputs 66 in the serial monitor?
The array is declared to small.
There is no array at all.
int conn[][1] = {};
void setup() {
Serial.begin(115200);
Serial.print(F("bytes used for conn: "));
Serial.println(sizeof(conn));
}
void loop() {}
bytes used for conn: 0
How do I create a two-dimensional array that I can add integers to? My plan is to have an array like {{4,5},{2,7},{5,8},{3,1}...}
that I can infinitely increase. This is my first time trying to make an array in Arduino; I only used Python.
You can not do it, arrays can not be grown in size.
You start with a sized array say arrayOriginal[10]
and when you need to add more elements you copy your original array to a holding array and then destroy arrayOriginal, and then recreate arrayOriginal to the new size and then copy the holding array back to arrayOriginal. In Python all the code is done for you, in C++ you'll have to write the code.
Now, do you have infinite ram?
Oh, I didn't know that, thanks. Is there a way then to make a sort of something, where I can store around 15(but not a fixed number) arrays of two numbers?
But you know C++?
If not, you should learn it.
As a Python programmer, you don't have to learn programming, just the language itself.
C++ is very different from Python, being strongly typed,
everything has to be declared before used, and barely any built-in introspection.
You can do anything in C++, if you have the memory, which is rarely the case.
An UNO sports 2k of RAM, there is no room for dynamic memory to speak of.
you should define the array as follows for an Nx2 array allow conn [0][0] and conn [0][1], but not conn [0][2] and up to conn [N-1][1]
int conn[N][2] = {};
Another why !! Why do you post screenshots of code? Please read About the IDE 1.x category and in future post code using code tags please.
Is your array static or (kind of) dynamic. That is, are the values set once or not?
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.