Thread: Pointer

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    All data is stored in memory at a specific address. So a little char like this
    char foo = 'a'

    is stored as 97 (the ascii code for a) in a byte of memory.

    This byte of memory has an address that the system uses to locate it. The address can be pretty much anything the program is allocated by the operating system (attempting to read/write/execute stuff outside of the space allocated by the operating system can lead to the operating system killing your program and throwing up an error (GPF or Segfault), because you're not allowed to do that).

    so lets say this foo's address (&foo) is 600. and we make a pointer to it called bar.

    char *bar = &foo

    Now bar itself takes up 4 bytes of memory (on a 32-bit system). bar is a pointer. All bar contains is the address of foo, 97. You can pass bar to functions and this allows functions to edit foo (thus avoiding complicated returns).

    Pointers are very important, and you'll see and use them alot. Unless you decide to program in java or something.

    misinformation is a gift.
    Last edited by Brian; 08-03-2003 at 03:10 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  2. Quick Pointer Question
    By gwarf420 in forum C Programming
    Replies: 15
    Last Post: 06-01-2008, 03:47 PM
  3. Parameter passing with pointer to pointer
    By notsure in forum C++ Programming
    Replies: 15
    Last Post: 08-12-2006, 07:12 AM
  4. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM