开发者

Location of static pointed memory

开发者 https://www.devze.com 2023-01-15 07:54 出处:网络
I read that pointers passed by malloc() & calloc() get allocated memory dynamically from the heap.

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?


  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)
0

精彩评论

暂无评论...
验证码 换一张
取 消