(First post here so I apologize in advanced if there's a formatting issue I missed when reading the rules)
Probably a lot simpler than I'm making this out to be. Its my understanding that you can add 2 integers, but I can't figure out how to add 2 arrays, or how to add an integer and an array.
ex1 (adding integers):
int a = 1;
int b = 2;
void setup(){
Serial.begin (9600);
}
void loop() {
int answer = a + b;
Serial.print(answer);
}
This will compile.
ex2 (adding arrays):
int a[2] = {1,2};
int b[2] = {3.4};
void setup(){
Serial.begin (9600);
}
void loop() {
int answer = a + b;
Serial.print(answer);
}
This gives me the following errors
" error: invalid operands of types 'int [2]' and 'int [2]' to binary 'operator+'
int answer = a + b;"
warning: narrowing conversion of '3.4000001e+0' from 'double' to 'int' inside { } [-Wnarrowing]
int b[2] = {3.4};
And lastly ex3 (adding an integer and an array):
int a = 1;
int b[2] = {2.3};
void setup(){
Serial.begin (9600);
}
void loop() {
int answer = a + b;
Serial.print(answer);
}
This compiles, but still gives the errors
" warning: narrowing conversion of '2.29999995e+0' from 'double' to 'int' inside { } [-Wnarrowing]
int b[2] = {2.3};
and
warning: invalid conversion from 'int*' to 'int' [-fpermissive]
int answer = a + b;"
So if someone could help me understand what the computer is actually doing with these functions, I'd really appreciate it.
How I understood it, I thought adding integers would work like adding 2 constants, so it would compile (which it did).
I thought adding arrays would add each section to the matching section (ex: first int in array 1 is added to the first int in array 2, 7th int in array 1 is added to 7th int in array 2 etc.) which doesn't seem to be the case.
And finally, I thought adding an integer to an array would either A. Not work at all because its adding 1 number to 5, or B. it would add the integer individually to each value in the array (ex: if the integer was 1, and the array values were 1 and 2, it would return the values 2 and 3 for the array). Which also doesn't seem to be the case.