|
-
Jan 24th, 2002, 01:31 PM
#1
Thread Starter
Addicted Member
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
-
Jan 24th, 2002, 01:52 PM
#2
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.
-
Jan 24th, 2002, 02:03 PM
#3
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|