neonz
1
int irValue = 1;
void loop() {
if (irValue==1) {
int array_data[3] = { 1,2,3 };
} else {
int array_data[3] = { 4,5,6 };
}
Serial.println(array_data[2]);
delay(10000);
}
'array_1' was not declared in this scope
it's not work.
I want to select the value of array_1 according to irValue.
What should i do?
Hello
show you complete sketch to be forwarded in code tags </> to see to help you.
gcjr
3
you can use preprocessor commands
#if 1
int array_data[3] = { 1,2,3 };
#else
int array_data[3] = { 4,5,6 };
#endif
Does
int array_data1[3] = {1,2,3};
int array_data2[3] = {4,5,6};
int* array_data = (irValue==1) ? array_data1 : array_data2;
work?
gcjr
5
static initialization, outside of a function call, occurs at compile time. the approaches you're suggesting occur at run-time.
why don't you just ask the compiler and try it?
system
Closed
6
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.