1
プログラム1:ヌルポインタ例外(チャー対INT)
#include <iostream>
using namespace std;
int main()
{
int *ptr = NULL;
cout << "The value of ptr is " << ptr ;
return 0;
}
プログラム2:
#include <iostream>
using namespace std;
int main()
{
char *ptr = NULL;
cout << "The value of ptr is " << ptr ;
return 0;
}
質問は、プログラム1で出力が安定であるとして:
The value of ptr is 00000000
プログラム2では、intポインタの代わりに私はcharポインタを使用し、それは私に例外を与えます。
誰でも私の理解を助けることができますか?
charポインタの場合の逆参照を避けることはできますか? –
@MukeshPareek [this duplicate](https://stackoverflow.com/questions/10869459/char-pointer-confusing-with-cout-in-c)を参照してください。 – WhozCraig
char *をint型にキャストできます:(int)ptr – kcraigie