Pointers and NULL

This is a discussion on Pointers and NULL within the C++ Programming forums, part of the General Programming Boards category; Ive' been wondering about pointers i know they are quite important in C++ but what exactly do they do? I ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    2

    Question Pointers and NULL

    Ive' been wondering about pointers i know they are quite important in C++ but what exactly do they do? I would also like to know what NULL means. I think it means something like no value or 0, but im not sure, please tell me. Any help would be great.

  2. #2
    Registered User kitten's Avatar
    Join Date
    Aug 2001
    Posts
    109
    NULL doesn't really mean anything else but a pointer with value of zero. This generally indicates that the pointer isn't pointing to anywhere.

    A pointer is an address to an object in memory. So if I have a pointer to int called pInt. The value inside pInt is that specific location where the variable int is in memory.
    Code:
    int a = 10;
    int* pInt = &a;  // declare a pointer to int type data and set a's address to it
    Same thing if you have an array of int's. Usually the pointer points to the first element in array, and all the other elements can be pointer via the pointer.
    Code:
    int array[100];
    int* pArray = &array[0];  // 1
    int* pArray = array;  // 2
    // cases 1 and 2 are exactly the same thing
    
    cout << *pArray;  // print out the first element in array
    cout << *(pArray+1);  // print out the second element in array
    Making error is human, but for messing things thoroughly it takes a computer

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory leaks problem in C -- Help please
    By Amely in forum C Programming
    Replies: 14
    Last Post: 05-21-2008, 11:16 AM
  2. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  3. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 08:32 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21