Thread: pointers and array

  1. #1
    Registered User
    Join Date
    May 2009

    pointers and array

    hi everybody,
    today i was reading a tutorial on C++ on <> and there it is wriitten in pointer and array Initialization section:"It is important to indicate that terry contains the value 1702, and not 'h' nor "hello", although 1702 indeed is the address of both of these."
    Now i write a very simple program and compile it with gcc:
    using namespace std;
    int main(){
    	char * terry = "hello";
    	cout << terry << endl;
    and its output is : "hello"
    If terry does not contain "hello", the output should have been some address.

    Pls help me to understand the concept.


  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    char* is a special case, in that 99.9% of the time it makes more sense to print the string it points to rather than the pointer itself.

    To print the actual pointer itself, try
    cout << reinterpret_cast <void*> (terry) << endl;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. array of pointers to an array pointers
    By onebrother in forum C Programming
    Replies: 2
    Last Post: 07-28-2008, 11:45 AM
  2. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM