我不記得我讀的是哪裏,如果我將一個字符串傳遞給函數。 C字符串,常量,複合文字以及爲什麼不是,代碼本身的持續時間
char *string;
string = func ("heyapple!");
char *func (char *string) {
char *p
p = string;
return p; } printf ("%s\n", string);
字符串指針繼續有效,因爲「heyapple!」在內存中,它在我寫的代碼中,所以它永遠不會起飛,對吧?
而關於常數像1,2.10,'a'?
和複合文字?
就像如果我這樣做:
func (1, 'a', "string");
Only the string will be all of my program execution, or the constans will be too?
For example I learned that I can take the address of string doing it
&"string";
Can I take the address of the constants literals? like 1, 2.10, 'a'?
I'm passing theses to functions arguments and it need to have static duration like strings without the word static.
Thanks a lot.
其實''heyapple!\ 0'在內存中。 – 2011-02-28 18:33:32