嘿傢伙我試圖打印出字符串文字的地址和命令行參數的開始和結束。字符串文字和命令林德論點的地址
int main(int argc, char *argv[]) {
printf("Address of argc: %p\n", (void*)&argc); //Is this how u find the address of argc?
//How to find out the start and end of command line arguments?
printf("Start of argv: %p\n", (void*)argv); //Like this? I am not sure...
char* strLiteral = "Hello world";
//how to find the address of "Hello world"? (Address of string literal)
}
我做了我的研究,並且我聽到類似字符串文字的地址這樣的答案是不允許的......這是真的嗎?這是什麼意思?字符串文字沒有地址?請告訴我如何獲得命令行參數的開始和結束地址。 感謝您抽出寶貴時間。
「我聽說過類似於接受字符串字面值的答案是不允許的」 - *你在哪裏聽到了?那? **不允許向所述地址位置寫入**。以只讀方式使用這些地址,否則就不可能將它們發送給任何需要「const char *」的函數(例如,像printf一樣用'%s'指定符來引發)。如果你不能使用他們的地址,他們將毫無價值。 – WhozCraig
from here http://stackoverflow.com/a/12601183/859385 – user859385
你與user6146524有關嗎?請參閱:http://stackoverflow.com/questions/36368780/are-we-able-to-print-out-the-address-for-string-literal –