This is more of a theory question, then any actual code.
I understand that if you declare a variable
int i; then it sets aside 4 bytes in memory for the integer i.
I understand if you use malloc to create your memory as well.
I am curious how memory is handled when you do something like
int x;
int y;
double z;
z = (float)x/(float)y;
When you cast like this, how is the memory handled. Does the program create floats and store x and y and then do the division? Or is it something outside of memory?
Thanks for any explanation!
Yes, the straightforward way is to create temporary variables – usually on stack. In some cases the compiler can be able to optimize the unnecessary temporary variables creation away. If you really care you should look into the produced disassembly.