You must cast &array[i]
to void*
for(int i =0; i<10;i++){
std::cout<<(void*)&array[i]<<std::endl;
}
This is because C++ streams work differently for different types. For example when you pass char*
to it, your data is treated as a C-string - thus it is printed as a list of characters.
You must explicitly tell C++ that you want to print an address by casting.
By the way (void*)
is not the best way to do that as you should avoid C-like casting. Always use C++-style casting (static_cast
, dynamic_cast
, reinterpret_cast
). In this case static_cast
would do the job.