请参阅以下声明:
char a[5]="jgkl"; // let's call this Statement A
char *b="jhdfjnfnsfnnkjdf"; // let's call this Statement B , and yes i know this is not an Array
char c[5]={'j','g','k','l','\0'}; // let's call this Statement C
Run Code Online (Sandbox Code Playgroud)
现在,陈述A和C之间有什么区别吗?我的意思是两个都应该在Stack上吗?只有b将位于静态位置.
那么在程序的整个生命周期中,不会使"jgkl"存在于静态位置吗?既然它应该是只读/常数?请澄清.
假设我有一个数组(函数的本地)和一个指针
char a[]="aesdf" 和 char *b="asdf"
我的问题是,在前一种情况下,字符串文字"aesdf"是存储在只读部分,然后复制到本地数组还是类似于
char a[]={'a','e','s','d','f','\0'}; ?
我认为在这种情况下,字符直接在堆栈上创建,但在前面的case(char a[]="aesdf")中,字符从只读部分复制到本地数组.
在可执行文件的整个生命周期中是否存在"aesdf"?