Well whenever you start doing undefined things, there's no telling what 'answers' you're going to get.
Code:
#include <stdio.h>
void memdump ( const char *p, size_t len ) {
char ascii[17] = { 0 };
for ( size_t i = 0, c = 0 ; i < len ; i++ ) {
char b = p[i];
if ( b >= 32 && b <= 126 ) ascii[c++] = b;
else ascii[c++] = '.';
printf("%02x ", (unsigned char)b);
if ( c == 16 ) {
printf("%s\n", ascii );
c = 0;
}
}
}
int main(){
char a1[6]={"Bhopal"}; // here output is 12
memdump(a1,16);
char a2[5]={"Bhopa"}; // here output is 10
memdump(a2,16);
char a3[4]={"Bhop"}; // here output is 8
memdump(a3,16);
return 0;
}
$ gcc -std=c99 foo.c
$ ./a.out
42 68 6f 70 61 6c 00 00 20 07 40 00 00 00 00 00 Bhopal.. .@.....
42 68 6f 70 61 00 00 00 d0 04 40 00 00 00 00 00 Bhopa.....@.....
42 68 6f 70 ff 7f 00 00 00 b0 7d 1e 63 89 c6 ba Bhop......}.c...
Bhopal and Bhopa would apparently work for me, but I wouldn't call that 'success' because I know the code is wrong.