Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
何が違うのか気になる
char* str[NUM]; char str[NUM]; char* str;
私の理解では、真ん中のような配列定義は、最初の値のアドレス、つまりstr[0]. しかし、コードの最初の行、つまり配列へのポインターによって表される表記も見られます。これら3つは同等ですか?配列定義が文字のスタックにスペースを設定することは知っているNUMので、おそらくそれは単に
str[0]
NUM
char* str?
ありがとう
char* str1[NUM]; // an array of size NUM of pointers to char char str2[NUM]; // an array of size NUM of char char* str3; // a pointer to char
これらの用途は次のとおりです。
str1[NUM-1] = strdup("foo"); strcpy(str2, "foo"); str3 = strdup("foo");