tags:

views:

56

answers:

1

I read that pointers passed by malloc() & calloc() get allocated memory dynamically from the heap.

char *Name="Ann";
  1. In this case, is the static string {'A','n','n','\0'} also stored in the heap?
  2. Can I modify the string using the pointer?
+7  A: 
  1. No, the string is allocated statically. (C99, §6.4.5/5)
  2. Attempting to modify a string literal gives undefined behavior. (§6.4.5/6)
Jerry Coffin