Thread: The Mysterious char*

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User Waleed Mujeeb's Avatar
    Join Date
    Jan 2012
    Posts
    22

    The Mysterious char*

    I have always been confused about the working of char* pointer.
    It seems to behave quite strangely.

    Unlike the int or float pointer, the char* pointer seems to be able to store an address and also a string?
    1.can some one explain this dual behavior of char*?

    Code:
    Program
    
    int main( )
    {
    char* p;
    
    //Works
    p="Hello";
    
    //Prints correctly
    cout<<p;
    
    //Does not work
    cin>>p;
    
    return 0;
    
    }
    2.why p="Hello" works? its a pointer shouldn't it give an error because "hello" is not an address, its a string?

    3. And why cin>>p doesn't work?
    Last edited by Waleed Mujeeb; 05-14-2012 at 10:39 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mysterious error
    By deeisenberg in forum C Programming
    Replies: 8
    Last Post: 04-30-2012, 03:51 PM
  2. mysterious seg fault!
    By MK27 in forum C++ Programming
    Replies: 12
    Last Post: 03-12-2010, 02:29 AM
  3. Mysterious Seg Fault
    By Akalic in forum C Programming
    Replies: 6
    Last Post: 10-26-2009, 04:16 PM
  4. mysterious code.......(??)
    By deltabird in forum C Programming
    Replies: 7
    Last Post: 04-11-2003, 03:58 PM
  5. Mysterious message from vVv
    By sean in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 06-08-2002, 04:11 PM