2
這可能是一個新手的問題,但這裏是我的問題:訪問字符串數組的第一個元素用C
我要聲明字符串數組但是當我訪問的第一要素,其他要素獲取與它連接起來。
#include <stdio.h>
int main(){
char words[2][3] = {"foo", "bar"};
printf("%s\n", words[0]); // I want to print foo
printf("%s\n", words[1]); // I want to print bar
}
,輸出
foobar
bar
雖然我期待
foo
bar
有人可以解釋:
- 剛纔發生了什麼?
- 如何獲得我期待的行爲?
您想了解C-「字符串」是什麼以及如何處理它們。 – alk