I have an embedded systems course in my university and i have a weird question that i don't know the answer to the question gives us the code (i may have a syntax error but the logic is correct)
void modify() {
static volatile int counter = 0;
printf(counter++);
}
int main() {
modify();
modify();
}
and the question asks "For the following code, True or False and justify: the program output will always be 0 1, assume the program is stored on the flash memory and the program is executed from the start every time it is run" when i tried running a similar code on arduino it resetted and started from zero but i have this weird question in the reference and i feel they are similar (i have attached the question) Another question from my reference "INTRODUCTION TO EMBEDDED SYSTEMS A CYBER-PHYSICAL SYSTEMS APPROACH"
counteris initiliased once. So the output from successive calls is0 1 2 3 . . .etc.printf(counter++);is not a valid call for the standard Cprintffunction.printf(counter++);implies you should post true code and true output. If the output is not as desired, post the desired output. "i think it shouldn't do that" does not say what you think it should be.printf( "%d\n", counter++);or similar, then the output would be 0 then 1, the likely result of returning from main would be to either restart or halt indefinitely, so you might see 0 then 1 repeatedly or just once. Arduino is a different matter, it's setup/loop framework is not compatible with the code you posted. The framework includes a main that executes setup/loop. You ought to post the exact code you are asking about, not something merely resembling it. Statically allocated data as in your question and link are initialised once and retain thier value across calls