#include <iostream> #include <cstring> using namespace std; int main(){ char a[80]="teratail"; cout << a << endl;
上のコードが何の問題もなく,実行されるのに対し,下のコードだとエラーが生じる原因が分かりません。
#include <iostream> #include <cstring> using namespace std; int main(){ char *a[80]="teratail"; cout << *a << endl;
もう一つ,
#include <iostream> #include <cstring> using namespace std; int main(){ char b[80]; strcpy_s(b,"teratail"); cout << b << endl;
は普通に問題なく実行してくれるのですが,以下のコードだとエラーが起きる原因が分かりません。
#include <iostream> #include <cstring> using namespace std; int main(){ char *b[80]; strcpy_s(*b,"teratail"); cout << *b << endl;
何かの本で,ポインタ変数と言えど*を付ければ普通の変数として扱えるとあったので,うまくかと思いきや,上のような結果になったので困惑しています。
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。