0

How does memory gets allocated for a string literal in C and do we need to free it? E.g.:

char *k="hello world";

Where does this string get stored and how does it get de-allocated?

Yun
  • 3,056
  • 6
  • 9
  • 28
Karthick
  • 1,010
  • 1
  • 8
  • 24

1 Answers1

1

where does this string get stored

Usually in read-only memory, you cannot modify it. In gcc, on most systems, they are located in the .TEXT section.

how does it get de-allocated

upon program termination.

Yun
  • 3,056
  • 6
  • 9
  • 28
Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261