read only memory in C/C++

C & C++ 2014. 7. 14. 12:46
반응형


What is the difference between char s[] and char *s in C?


http://stackoverflow.com/questions/1704407/what-is-the-difference-between-char-s-and-char-s-in-c





How is read-only memory implemented in C?


http://stackoverflow.com/questions/1704893/how-is-read-only-memory-implemented-in-c






http://effserv.tistory.com/131






http://www.linuxquestions.org/questions/programming-9/why-char-%2A-is-called-read-only-memory-%5Bc-c-%5D-171014/#post4136372


  // This is allocated from the heap with the C++ "new" operator
  // It's read-write
  // You must use "delete" to dispose of it
  char* str1 = new char[20];

  // This is allocated from the heap with the C "malloc()" function
  // It's also read-write
  // You must use "free()" to dispose of it
  char* str2 = malloc (20);

  // This is allocated from the stack
  // It, too, is read-write
  // It's disposed of when then block exits (usually, at the end of the function)
  char* str3[20];

  // This is a constant
  // It is READ-ONLY
  // You MUST NOT try to write to it!
  char* str4 = "Hi.123456789";








반응형
Posted by 자유프로그램
,