-
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
-
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.
-
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.