0

I am learning C++ and I came across string literals. I am wondering where strings literals are stored in C++ (stack or heap) ?

R Sahu
  • 204,454
  • 14
  • 159
  • 270
  • 1
    Neither, they are kept in the static memory space, where the rest of your program is. – Loocid Mar 23 '21 at 04:49
  • The terms "stack" and "heap" are generally meaningless in C++ - they are terms associated with some specific implementations. Objects in C++ have storage duration, such as automatic (only exist until the end of their containing scope), static (exist from point in time when they are created), and dynamic (manually allocated and released). A string literal is represented as an array of `char` with static storage duration. It's actual location in physical or logical memory depends on the implementation (e.g. it is a design decision by developer of the compiler). – Peter Mar 23 '21 at 09:21

0 Answers0