以下の特定のプログラムに関連するいくつかの疑問があります。どんな議論も内部を理解するのに役立ちます。
#include <iostream>
using namespace std;
int main() {
// your code goes here
char* ptr = new char[11];
ptr = "helloworld";
cout << ptr;
int* ptr1 = new int[2];
//ptr1 = {12, 24};
cout << ptr1;
return 0;
}
- cout << ptr; helloworld を出力します (値を出力します)。cout << ptr1 は、値ではなくアドレスを出力します。どうして??
- cout << ptr; 以来。値を出力します。新しい char[11] が ptr に割り当てるアドレスを取得する方法。
- If ptr = "helloworld"; 許可されています。なぜptr1 = {12、24}; 許可されていませんか?