+ 3

Can array be printed like cout<<arr;

13th Mar 2018, 12:32 PM
abishek samuel
abishek samuel - avatar
3 odpowiedzi
+ 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...
13th Mar 2018, 12:39 PM
🌛DT🌜
🌛DT🌜 - avatar
+ 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; }
13th Mar 2018, 1:17 PM
Hatsy Rei
Hatsy Rei - avatar
+ 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
13th Mar 2018, 1:04 PM
Ashraf Al_Absi
Ashraf Al_Absi - avatar