#include <stdio.h>
#include <string.h>
int main() {
char* p = new char[10];
memset(p,0,10);
printf("%c",*p);
}
I suppose memset set every byte starting p to 0. I’m a little surprised to see nothing at all printed out. What on earth was happening for memset?
memsetdoes set all the bytes to 0; thus, when you dereferencep, you get acharwith value 0 (the NUL byte), and on most systems, printing such acharproduces no visible output. If you want to print the numeric value of the byte instead, useprintf("%d", *p);.