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.
次のコードの違いは何ですか?
1.
char *p; strcpy(p,"String");
2.
char *p; p = "String";
ポインタは同じ文字列を指していますが、違いはありますか?
最初のポイントで、文字列を p が指している memblock にコピーしたいと言っています
(そのため、文字列をコピーできる十分なスペースがあることを確認する必要があります)
2 番目のケースでは、"String" の読み取り専用アドレスを指す p を作成します。
p -> [S][t][r][i][n][g][0]
ただし、 p を次のように宣言しない限り、コンパイラの警告が表示されるはずです。p const *
p const *