I'm new to c++, and I want to pass a float array out of a function using a pointer. However, the returning array is always 0; I am running on an Arduino Uno.
This is my code. I want the readSensor() function to pass out a float array consisting of 3 floats. The float array should be pass to the pointer output*. But when I print out readings, it shows 0.00 instead of the values I passed out.
void setup() {
Serial.begin(9600);
}
void loop() {
float readings[3];
readSensor(readings);
for (int i = 0;i < 3;i++) {
Serial.println(readings[i]);
}
delay(1000);
}
// pass out these 3 floats
float val1 = 3.14159;
float val2 = 2.741;
float val3 = 87;
void readSensor(float* output) {
float container[3] = {val1, val2, val3};
output = container;
}
std::array, not dumb arrays, and then most of your code would remain the same.