heap vs data segment vs stack allocation

前端 未结 2 1809
醉话见心
醉话见心 2021-02-05 12:35

Am looking at the following program and not sure how the memory is allocated and why:

void function() {
    char text1[] = \"SomeText\";
    char* text2 = \"Some         


        
2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-05 12:58

    Yes you are right, on most systems:

    text1 will be a writable variable array on stack (it is required to be a writable array)

    text2 has to be const char* actually, and yes, it will point to a text segment of the executable (but that might change across executable formats)

    text will be on heap

提交回复
热议问题