Thread: Do I understand pointers correctly?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    C(++)(#)
    Join Date
    Jul 2004
    Posts
    309

    Do I understand pointers correctly?

    Ok, I'm trying to see if I understand points correctly. Here is how I understand them:

    1) Pointers act as a variable that points to the memory adress of another variable:
    Code:
     
    int a = 10;
    int *b= &a;
    2) When dereferenced, you can output the value of the variable the pointer references:
    Code:
    std::cout<<*b<<endl;
    OUTPUT: 10
    3) When not dereferenced, you can output the memory adress of the variable the point references. Which can later be used to read the memory of a variable from another application (such as in a minesweeper cheat):
    Code:
    std::cout<<b<<endl;
    OUTPUT: *bunch of hex*
    4) Pointers can be used to pass by reference, so that a variable can be modified by a function without having to return it - allowing for the modification of multiple variable within a function:
    Code:
     
    int inc(int a, int *b)
    {
        a++:
        *b = 20;//Is this legal?
        return a;
    }
    int f = 0;
    int g = 1;
    inc(f, &g)//f is now 1, g is now 20

    Ok, that's all I can think of right now. However, I want to know if I am right on those four points, and if there is anything else I should know.


    EDIT: Yeah yeah, this is the 5 trillionth post on pointers, I know. However, unless I ask myself I won't be sure
    Last edited by 7smurfs; 01-04-2006 at 12:29 PM.
    To code is divine

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. man -k (how to use correctly)
    By cus in forum Linux Programming
    Replies: 2
    Last Post: 01-14-2009, 11:00 AM
  2. Did I Install the Platform SDK Correctly?
    By bengreenwood in forum C++ Programming
    Replies: 7
    Last Post: 07-14-2008, 09:33 AM
  3. strange error -- COM DLL is not installed correctly?
    By George2 in forum C# Programming
    Replies: 0
    Last Post: 07-16-2007, 08:32 AM
  4. inputFn with hash not assigning pointer correctly
    By mackol in forum C Programming
    Replies: 1
    Last Post: 11-22-2002, 11:17 PM
  5. Why does this not read in correctly?
    By bluebob in forum C Programming
    Replies: 9
    Last Post: 04-19-2002, 09:17 AM