Is the first variable declared in C at the topmost point of the stack or not? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Is the first variable declared in C at the topmost point of the stack or not?

Suppose this code: char buf; *(&buf + 1) = 'a'; putchar(*(&buf + 1)); Where does character 'a' get stored, if &buf is at the top of the stack?

6th May 2021, 6:45 PM
Calvin Thomas
Calvin Thomas - avatar
3 Answers
+ 1
Martin Taylor In SoloLearn, the first variable declared has the highest address. So what occurs above the stack, here? I had thought that in C, there is a direct connection between the variable-number and the position of it on the stack.
6th May 2021, 7:40 PM
Calvin Thomas
Calvin Thomas - avatar
+ 1
Martin Taylor Thank you for the explanation. That really helped me.
7th May 2021, 4:49 AM
Calvin Thomas
Calvin Thomas - avatar
0
Martin Taylor So the compiler checks for such situations and raises an error when such a thing happens. Thanks for the explanation.
6th May 2021, 7:58 PM
Calvin Thomas
Calvin Thomas - avatar