Answers for "Dynamically allocated in heap segment."

0

Dynamically allocated in heap segment.

char *str;
int size = 4; /*one extra for ‘\0’*/
str = (char *)malloc(sizeof(char)*size);
*(str+0) = 'G';
*(str+1) = 'f'; 
*(str+2) = 'G'; 
*(str+3) = '\0'; 
Posted by: Guest on June-30-2021
0

Dynamically allocated in heap segment.

int main()
{
 char *str;
 str = "GfG";     /* Stored in read only part of data segment */
 *(str+1) = 'n'; /* Problem:  trying to modify read only memory */
 getchar();
 return 0;
}
Posted by: Guest on June-30-2021

Browse Popular Code Answers by Language