#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
int main()
{
     const int N = 4; // consider = sizeof(char*) instead

     // your memory allocation
     char* buffer = static_cast<char*>(malloc(N));

     // the pointer b will accesses the value of buffer as if it was a char array
     char* b = reinterpret_cast<char*>(&buffer);

     // copy the char array from b to where buffer is pointing
     std::copy(b, b + N, buffer);

     // output
     printf("The pointer returned by malloc was %p\n", buffer);
     printf("The contents of buffer[0]-buffer[%d] are: ", N-1);
     for(int i=0; i<N; ++i)
         printf("0x%02x ", (unsigned char)buffer[i]);
     printf("\n");

     free(buffer);
}