dポイントプレゼントキャンペーン実施中!

以下のプログラムを使ってポインタの勉強していますが、warningがでてしまします。
何が原因でしょうか。


#include<stdio.h>

int main(void){

int a=1;

printf("%d,%x",a,&a);

return 0;

}

**** Rebuild of configuration Debug for project listex2-1 ****

**** Internal Builder is used for build ****
gcc -O0 -g3 -Wall -c -fmessage-length=0 -o main.o ..\main.c
..\main.c: In function `main':
..\main.c:13: warning: unsigned int format, pointer arg (arg 3)
gcc -o listex2-1.exe main.o
Build complete for project listex2-1
Time consumed: 625 ms.

A 回答 (2件)

警告だけなんで、とりあえず動作はします。



https://oshiete.goo.ne.jp/qa/420477.html
gccだとprintf()のフォーマット書式と引数の型のチェックもしているのでしょう。
で、ポインタの場合は%pとすべき。という警告かと。
&aをunsigned intなりにキャストすれば…という対策もありかと。
    • good
    • 1
この回答へのお礼

ありがとうございます。

お礼日時:2017/12/23 13:29

%xがマズいんじゃないんですか?

    • good
    • 1
この回答へのお礼

ありがとうございます。

お礼日時:2017/12/23 13:29

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!