The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM



Thread: Heap and stack
View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 04-27-2008
andryk's Avatar
andryk andryk is offline
Registered User
 

Join Date: Sep 2003
Posts: 448
Hi,
It'll be on stack i suppose and in general all variables declared inside a function will be on stack as well.
You can print the address of where a resides and print the value of stack pointer (SP) you then should have the same base address ...
Code:
unsigned long sp(void) {
   asm("movl %esp, %eax");
}
void main() {
  int *a;

  a=malloc(16*sizeof(int));
  printf ("addr of a is %p, sp is %p and malloc is %p\n",&a,sp(),a);
}
Of course i assume you're on intel-based !

Last edited by andryk; 04-27-2008 at 11:44 PM.
Reply With Quote