Thread: a bit confused with char string~

  1. #1
    flashing vampire black's Avatar
    Join Date
    May 2002
    Posts
    563

    a bit confused with char string~

    as we know something like this would get the value of the pointer: *pt
    and this would get the adress what the pointer point to: &pt

    but when I experiment this to char strings I got the different response.

    for example:

    void main()
    {
    char arr[]="Hello World";
    cout << &arr << endl;
    }

    Let's check what we get.
    Never end on learning~

  2. #2
    Unregistered
    Guest

    Re: a bit confused with char string~

    Originally posted by black
    void main()...

    Let's check what we get.
    We get slapped on the wrist for using void main.

  3. #3
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    arr is a pointer
    &arr is the address of that pointer variable
    *arr is the value of the char the pointer points to

    what are you trying to do with that code?
    i got 0xbffffa4c if you're interested

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Code:
    #include <iostream>
    
    int main()
    {
      char arr[] = "Hello World";
    
      // This should print an address
      std::cout<< &arr <<std::endl;
      // This should print the contents of arr
      // ie. Hello World
      std::cout<< arr <<std::endl;
      // This should print H
      std::cout<< *arr <<std::endl;
      
      return 0;
    }
    So &arr does what we expect, it returns the address of the first element of the array. *arr does as we expect as well, it returns the value of the first element of the array. Since cout assumes that you want to print the array when you give it arr, it does so instead of printing the contents of arr, which is an address.

    >void main()
    I've explained this to you before, what's your excuse for still using it?

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. Replies: 12
    Last Post: 08-11-2008, 11:02 PM
  3. bit level permutation function
    By zxcv in forum C Programming
    Replies: 2
    Last Post: 07-27-2008, 01:26 PM
  4. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  5. lvalue error trying to copy between structures
    By emanresu in forum C Programming
    Replies: 2
    Last Post: 11-16-2006, 06:53 AM