a bit confused with char string~

This is a discussion on a bit confused with char string~ within the C++ Programming forums, part of the General Programming Boards category; as we know something like this would get the value of the pointer: *pt and this would get the adress ...

  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,493
    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,796
    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, 04:06 PM
  2. Replies: 12
    Last Post: 08-12-2008, 12:02 AM
  3. bit level permutation function
    By zxcv in forum C Programming
    Replies: 2
    Last Post: 07-27-2008, 02:26 PM
  4. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 10: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

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