Not getting my array printed out

Why is that I do not get the array myData outputed? ALl I get is a hex number
00BB8000

1
2
3
4
5
6
7
8
9
10
11

#include <iostream> 
using namespace std;

int myData[]{ 3,4,5,6,44,0};
int main()
{
    cout<<"THis is my array: "<<myData;
		cin.get();
    return 0 ;
}
Last edited on
To print out the contents of an array, iterate through the array and print each value.

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>

// http://www.stroustrup.com/bs_faq2.html#void-main
int main() // *** int main()
{
    const int myData[] { 3, 4, 5, 6, 44, 0 };

    // http://www.stroustrup.com/C++11FAQ.html#for
    for( int v : myData ) // for each int v in my data
        std::cout << v << ' ' ; // print out its value
    std::cout << '\n' ;
}
Because myData is an array of ints, when you use it, it's just like using the address to the first int in the array. So, when you try to print it, you're printing the address of the first int in the array. If you want to print the contents of the array, use a for each loop, like suggested above, or use a standard for loop with index:

1
2
3
4
for (int i = 0; i < size; ++i) {
  cout << myData[i] << ' ';
}
cout << '\n';
Topic archived. No new replies allowed.