I don't understand this thing. about memset in C
- I stored
john
inarray[]
. - Then I created
char* megaArray[10]
which can store 10 strings. - I assigned
megaArray[0] = array
. Sojohn
gets stored in 0 position ofmegaArray[]
. - I called
memset()
to resetarray[]
. array gets emptied. - Why does
tokens[0]
gets emptied if I calledmemset()
forarray[]
?
Please Help,
Here is the code
#include <stdio.h>
int main() {
char array[] = "john";
printf("%s is the name\n",array);
char* megaArray[10];
megaArray[0] = array;
printf("%s is the name in mega Array\n",megaArray[0]);
memset(array, '\0', sizeof(array));
printf("%s is the name after memset\n",array);
printf("'%s' is the name in mega Array after memset\n",megaArray[0]);
return 0;
}