Problem with arrays

Hello here , i have an problem in c++ , am trying to print an array ,

this array:

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


	int main(){
	
		int example[4] = {3, 6, 8, 10};

		std::cout<<example;



		return 0;
	}


but when i print this , the output is
0x22ff30

Why ?
Last edited on
It prints the memory address of the first element in the array. If you want to print the elements in the array you should use a loop.
example refers to a pointer, use:
for(int i=0; i<4; i++) {cout<<example[i];}
When you specify name of an array in an expression similar that you are using it is converted to a pointer to its first element. So the address of the first element is displayed.
To display elements of an array you should specify the array elements not the array itself.

For example

for ( auto x : example ) std:;cout << x << ' ';

Or

1
2
3
4
for ( size_t i = 0; i < sizeof( example ) / sizeof( *example ); i++ )
{
   std::cout << example[i] << ' ';
}
I understood, thanks.
Topic archived. No new replies allowed.