+ 3
Can array be printed like cout<<arr;
3 Answers
+ 20
No... it will print the address in hexadecimal format....
i guess u have to iterate to print the values of entire array....
OR for specific values
cout<<arr[index];
index start with 0.
u can use pointer too...
+ 11
You can overload it yourself, but it's not really practical.
#include <iostream>
const int SIZE = 10;
std::ostream& operator<<(std::ostream& obj, int arr[SIZE])
{
for (int i = 0; i < SIZE; i++)
obj << arr[i] << " ";
return obj;
}
int main()
{
int arr[SIZE] = {1,2,3,4,5,6,7,8,9,10};
std::cout << arr;
return 0;
}
+ 5
arrays are stored in a location in memory just like any variable but it only stores address whereas variables store values.
so when you use cout<<array it prints its address..
cout<<variable prints its value..
if you wish to print the values of an array you need to use any kind of loop statements