Thread: Stack and pointers

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    The only thing I can tell is that you don't get the same result when you do (int *)& to a pointer. You get the address of the memory of the pointer. That address you store it at the same pointer. So the pointer points itself. That is all. Don't know why you want to do this...

    EDIT: Hmm, you generally get a seemingly "random" number when you get the address of the pointer. But just guessing here, the programmer of this code might know that the return address of main is stored 2 memory blocks (each memory block stores one int) away from where p is stored. Why? Don't know, but p is the only local variable so you know, it is possible the program behaves like that. So you store the return variable on p. Then you change the value of the return address to what you want, and I assume main returns there.
    Last edited by C_ntua; 09-19-2008 at 11:45 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  2. Question about a stack using array of pointers
    By Ricochet in forum C++ Programming
    Replies: 6
    Last Post: 11-17-2003, 10:12 PM
  3. c / asm / stack and pointers
    By Lynux-Penguin in forum Tech Board
    Replies: 9
    Last Post: 08-06-2003, 12:08 PM
  4. Making a Stack using Pointers
    By Unregistered in forum C Programming
    Replies: 9
    Last Post: 07-27-2002, 11:51 AM
  5. Stack functions as arrays instead of node pointers
    By sballew in forum C Programming
    Replies: 8
    Last Post: 12-04-2001, 11:13 AM