###記憶域動的確保から解放された後、解放後のポインタが指す記憶域の中身を表示する
Microsoft Visual C++ 2010で作りました。
*p1=4321を書くと、free(p1);までは通りましたが、
その後のprintf("*p = %d\n", *p); printf("*p1 = %d\n", *p1);は通りません。
*p1=4321を削除すると、すべてが通ります。
###発生している問題・エラーメッセージ
デバッグの出力のウィンドウでは*.dllファイルが大量出現。 意味がよくわかりませんが、ヒントになるかもしれないと思ったので、載せました。 以下がその一部 'Practice3.exe': 'C:\Windows\System32\IMJP14K.DLL' を読み込みました。Cannot find or open the PDB file 'Practice3.exe': 'C:\Windows\System32\oleaut32.dll' を読み込みました。Cannot find or open the PDB file 'Practice3.exe': 'C:\Windows\System32\dwmapi.dll' を読み込みました。Cannot find or open the PDB file 'Practice3.exe': 'C:\Windows\System32\cryptbase.dll' を読み込みました。Cannot find or open the PDB file 'Practice3.exe': 'C:\Program Files\Common Files\microsoft shared\IME14\IMEJP\IMJPAPI.DLL' を読み込みました。Cannot find or open the PDB file 'Practice3.exe': 'C:\Program Files\Common Files\microsoft shared\IME14\SHARED\IMJKAPI.DLL' を読み込みました。Cannot find or open the PDB file 'Practice3.exe': 'C:\Program Files\Common Files\microsoft shared\IME14\IMEJP\IMJPPRED.DLL' を読み込みました。Cannot find or open the PDB file 'Practice3.exe': 'C:\Windows\System32\clbcatq.dll' を読み込みました。Cannot find or open the PDB file 'Practice3.exe': 'C:\Program Files\Common Files\microsoft shared\IME14\IMEJP\IMJPTIP.DLL' を読み込みました。Cannot find or open the PDB file 'Practice3.exe': 'C:\Windows\System32\oleacc.dll' を読み込みました。Cannot find or open the PDB file 'Practice3.exe': 'C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7601.18837_none_41e855142bd5705d\comctl32.dll' を読み込みました。Cannot find or open the PDB file 'Practice3.exe': 'C:\Program Files\Common Files\microsoft shared\IME14\SHARED\IMETIP.DLL' を読み込みました。Cannot find or open the PDB file 'Practice3.exe': 'C:\Program Files\Common Files\microsoft shared\IME14\SHARED\IMECFM.DLL' を読み込みました。Cannot find or open the PDB file
###該当のソースコード
C
1p = (int *)calloc(1, sizeof(int)); //int型整数用の記憶域を動的に確保 2 p1= (int *)malloc(2); 3 4 if (p == NULL) 5 puts("記憶域の確保に失敗しました。"); 6 else { 7 *p=1234; 8 printf("*p = %d\n", *p); 9 } 10 11 if (p1 == NULL) 12 puts("記憶域の確保に失敗しました。"); 13 else { 14 *p1=4321; 15 printf("*p1 = %d\n", *p1); 16 } 17 18 free(p); //確保していた領域を解放 19 free(p1); 20 21 printf("*p = %d\n", *p); //解放後のintの中身 22 printf("*p1 = %d\n", *p1); 23
###試したこと
*p1=4321;を削除する
###補足情報(言語/FW/ツール等のバージョンなど)
より詳細な情報
「通りました」「通りません」とは具体的にどういう現象ですか?
言い忘れました。「通る」と「通らない」は、ブレイクポイントのことです。ブレイクポイントを行毎に入れると、「*p1=4321」がある場合、「free(p1);」のブレイクポイントまでは通り、「printf("*p = %d\n", *p); 」と「 printf("*p1 = %d\n", *p1);」のブレイクポイントは通りません。コンソールの画面でもprintfが出力すべき文字列が見えません。よって、「free(p1);」を通った後、何らかのエラーで実行が中止してしまった可能性が考えられます。それはなんなのかを教えていただければ幸いです。
回答1件
あなたの回答
tips
プレビュー