Please explain some concepts about Pointer & Class & Array Pointer

This is a discussion on Please explain some concepts about Pointer & Class & Array Pointer within the C++ Programming forums, part of the General Programming Boards category; Pointers can be reassigned and can have NULL as a value. They can also simulate arrays. Your alternative, the reference ...

  1. #16
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,705
    Pointers can be reassigned and can have NULL as a value. They can also simulate arrays. Your alternative, the reference variable, cannot be reassigned and can not have NULL as a value, but removes a lot of the syntax involved in pointers. References are safer to use, but they do not completely replace pointers.

    One reason they don't replace pointers is because references are aliases for variables and not really types like pointers are. You cannot use a reference type in a std::vector for example. Another reason they don't replace pointers is because memory is not managed in C++ like in other languages; otherwise, a reference would be all you would need. Under the hood of just about any useful object are pointers allocated with new and so forth. So when you are using pointers, most of the time it is because there is no other choice.
    Last edited by whiteflags; 01-27-2010 at 04:00 PM.

  2. #17
    Noob AnishaKaul's Avatar
    Join Date
    Jan 2010
    Location
    Gurgaon, India
    Posts
    115
    Thanks to nadroj, your posts are a gentle reminder of the basic concepts

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. weird static char pointer array
    By Anator in forum C Programming
    Replies: 4
    Last Post: 11-16-2009, 06:05 AM
  2. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 04:01 PM
  5. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM

Tags for this Thread


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