Reputation: 88
Hi i had one of the interview question they were asked what is the starting address of the stack memory. Please i don't know the address can you please help how to find the starting address of the stack memory.
Thanks & Regards, Gunasekaran J
Upvotes: 1
Views: 1367
Reputation: 11400
There's no guarantees in C++ that there even is a stack. Even if, in practice, there's one, the place it is in memory varies by compiler implementation, platform, environment, etc...
There's OS features like address randomization that will even force the address to change from run to run. You can't try to determine it programmatically as the compiler is allowed to modify/optimize your code.
Basically, the way to answer this question is to explain what a stack is, that its size does vary, that the position is irrelevant. Then explain the purpose it serves and how it is typically implemented. You can go so far as talk about early/simple CPU and the registers that implement it.
Upvotes: 6