HI guys,
In the following code, I am trying to allocate some memory for a character array of size 30. PLease let me know what I am doing wrong. Because here, even after freeing the memory I still see the first element there same as before freeing the memory.
#include <stdio.h>
#include <stdlib.h>
char String[30];
char *pString = String;
//name of the array is synomus to the first element address?
int main(){
// printf(" %c\n",pString[0]);
pString = (char *)calloc(30, sizeof(char));
String[0] = 'a';
printf(" %c\n",String[0]);
free(pString);
printf(" %c\n",String[0]);
}
In the following code, I am trying to allocate some memory for a character array of size 30. PLease let me know what I am doing wrong. Because here, even after freeing the memory I still see the first element there same as before freeing the memory.
#include <stdio.h>
#include <stdlib.h>
char String[30];
char *pString = String;
//name of the array is synomus to the first element address?
int main(){
// printf(" %c\n",pString[0]);
pString = (char *)calloc(30, sizeof(char));
String[0] = 'a';
printf(" %c\n",String[0]);
free(pString);
printf(" %c\n",String[0]);
}