Results 1 to 3 of 3

Thread: newbie

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Location
    India
    Posts
    203

    newbie

    void main()
    {
    int arr[4]={1,2,3,4};
    cout<<arr;
    char abc[4]="hel";
    cout<<abc;
    }


    stupid Question..but still.. I wanna know why cout<<arr displays the address of the starting element of the array while cout<<abc displays the contents of the array??.. I mean shudnt all arrays have uniform features ?..kinda confusing fr beginers

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    This is because an array of char is interpreted as a string. An array of int is not, so it outputs the starting address of the array.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3
    Member lordsty's Avatar
    Join Date
    Oct 2001
    Location
    mD, Us
    Posts
    58

    Overloading

    Corned Bee is right, you have to loop through the integer array to print out each values of arr. The << operator defaults to printing out characters, strings,..(simple data structures). You will get to "operator overloading" in which you can make the statement cout<<arr print the integer array.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width