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
  • 2,536
  • 6
  • 7
  • 26
Karthick
  • 876
  • 1
  • 7
  • 22

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
  • 2,536
  • 6
  • 7
  • 26
Sourav Ghosh
  • 130,437
  • 16
  • 177
  • 247