volatile unsigned char x = 2
const unsigned char y = 123
My question is: Where is each variable stored? Are they both stored in the SRAM or flash? I tried to research online but I didn't manage to find anything useful
on an AVR, both will probably be stored in SRAM. On an ARM, the volatile will be stored in SRAM and the const will probably be stored in flash. This is mainly because the AVR flash is not accessible as "normal memory" to C programs, and you can't put any variables there.
For more fun, consider that "static const unsigned char z = 210;" will probably not be "stored" anywhere, but instead will be optimized in a way where it will be incorporated into expressions "as needed" (in a way, that's "stored in flash", but you won't be able to find it in a debugger, for example...)
OK, so there is no difference when it comes to where the variables are stored because the Arduino follows the AVR architecture. That means that both variables will be stored in the SRAM. Is that correct?
@PizzaGuy, not including a context, like which language, makes it impossible to give you a precise answer.
Assuming the two definitions are file-scope, the file is C++, and the address of y is never reference, then y is subjected to constant folding by the compiler and essentially disappears from existence. Which means it is not stored in SRAM. If y is referenced then the constant value (123) is stored in Flash as a load-constant machine instruction.