#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
char array[10];
for(int i = 0; i<10;i++)
{
array[i] = 'a' + i;
}
char* test = array;
printf("%x\n", test);
cout << hex << test << endl;
}
The output for this is:
bffff94e
abcdefghijN???
Why is it not printing the same thing?
It prints the string, not the address. It is because there is an overload of
operator<<which takeschar const*as argument and this overload treats the argument as string.If you want to print the address, cast the argument to
void*so that other overload ofoperator<<will be invoked which will print the address.will print the address, in hexadecimal format.
Note that
hexstream-manipulator is not needed here, as the address will be printed in hexadecimal format anway. Sois enough.