Which of the following pieces of code, in general, can result in an invalid memoryaccess? This question has multiple answers.
(A) char *str = (char*) malloc(10 * sizeof(char);
str[10] = ’\0’;
printf("%s", str);
(B) char *str = (char*) malloc(10 * sizeof(char);
str[0] = ’\0’;
printf("%s", str);
(C) char *str;
str[0] = ’\0’;
printf("%s", str);
(D) char *str = NULL;
str[0] = ’\0’;
printf("%s", str);
Can someone explain this question to me, I'm really confused?