###前提・実現したいこと
C言語で2つのポインタでデータとアドレスを表示するというコードを書いています。イメージの図は以下の様です。
コンパイル時に以下のようなエラーが出ています。
###発生している問題・エラーメッセージ
C
1% gcc -Wall ex2_2_1.c -o ex2_2_1 2ex2_2_1.c: In function 〓〓〓main〓〓〓: 3ex2_2_1.c:9:7: error: conflicting types for 〓〓〓p〓〓〓 4 int p = 5; 5 ^ 6ex2_2_1.c:5:7: note: previous declaration of 〓〓〓p〓〓〓 was here 7 int*p; 8 ^ 9ex2_2_1.c:10:7: error: conflicting types for 〓〓〓a〓〓〓 10 int*a; 11 ^ 12ex2_2_1.c:4:7: note: previous definition of 〓〓〓a〓〓〓 was here 13 int a = 10; 14 ^ 15ex2_2_1.c:14:10: warning: format 〓〓〓%d〓〓〓 expects argument of type 〓〓〓int〓〓〓, but argument 2 has type 〓〓〓int *〓〓〓 [-Wformat=] 16 printf("value of a =%d\n", a); 17 ^ 18ex2_2_1.c:15:10: warning: format 〓〓〓%p〓〓〓 expects argument of type 〓〓〓void *〓〓〓, but argument 2 has type 〓〓〓int〓〓〓 [-Wformat=] 19 printf("address of a =%p\n", p); 20 ^
###該当のソースコード
C
1#include<stdio.h> 2int main(){ 3 //a 4 int a = 10; 5 int*p; 6 p = &a; 7 8 //p 9 int p = 5; 10 int*a; 11 a = &p; 12 13 //print 14 printf("value of a =%d\n", a); 15 printf("address of a =%p\n", p); 16 printf("value of p =%d\n", p); 17 printf("address of p=%p\n", a); 18 return 0; 19} 20
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/11/12 05:36
2017/11/12 06:04
退会済みユーザー
2017/11/12 07:46