Alex Rivera | Logout

How to find if a variable is allocated in stack or heap?

Asked 2012-12-05T09:05:54.140
23

Stumbled upon this interview question somewhere,

In C, Given a variable x, how do you find out if the space for that variable is allocated on the stack or heap?

(Is there any way to find it out programatically and not having to go through the symbol table, etc? And does finding if the space is allocated in stack or heap has any practical implications?)

Edit
Report

1 Answer

1

I don't think it has solutions. The code may adjust var's address by stack(heap) address scope, but it's would not be an exact way. At most, the code can only run in some certain platforms.

answered 2012-12-05T09:13:52.437

Your Answer