質問するログイン新規登録

質問編集履歴

1

コードの修正

2017/11/12 05:34

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -2,28 +2,30 @@
2
2
  C言語で2つのポインタでデータとアドレスを表示するというコードを書いています。イメージの図は以下の様です。
3
3
  ![イメージ説明](e1eefd81c5254e55f14e5fa900804dac.png)
4
4
 
5
- まずは、アドレスを表示しようとードを書いたところ、以下のようなエラーが出てしま、どのように直せばいいのかわからず困っています。
5
+ ンパイル時に以下のようなエラーが出ています。
6
6
 
7
7
  ###発生している問題・エラーメッセージ
8
8
  ```C
9
+ % gcc -Wall ex2_2_1.c -o ex2_2_1
9
- ex2_2_1.c: In function main:
10
+ ex2_2_1.c: In function 〓〓〓main〓〓〓:
10
- ex2_2_1.c:9:7: error: conflicting types for p
11
+ ex2_2_1.c:9:7: error: conflicting types for 〓〓〓p〓〓〓
11
12
  int p = 5;
12
13
  ^
13
- ex2_2_1.c:5:7: note: previous declaration of p was here
14
+ ex2_2_1.c:5:7: note: previous declaration of 〓〓〓p〓〓〓 was here
14
15
  int*p;
15
16
  ^
16
- ex2_2_1.c:10:7: error: conflicting types for a
17
+ ex2_2_1.c:10:7: error: conflicting types for 〓〓〓a〓〓〓
17
18
  int*a;
18
19
  ^
19
- ex2_2_1.c:4:7: note: previous definition of a was here
20
+ ex2_2_1.c:4:7: note: previous definition of 〓〓〓a〓〓〓 was here
20
21
  int a = 10;
21
22
  ^
22
- ex2_2_1.c:14:10: warning: format %p’ expects argument of type ‘void *’, but argument 2 has type int [-Wformat=]
23
+ ex2_2_1.c:14:10: warning: format 〓〓〓%d〓〓〓 expects argument of type 〓〓〓int〓〓〓, but argument 2 has type 〓〓〓int *〓〓〓 [-Wformat=]
23
- printf("addressofa=%p\n", p);
24
+ printf("value of a =%d\n", a);
24
25
  ^
25
- ex2_2_1.c:15:10: warning: format %a’ expects argument of type ‘double’, but argument 2 has type int *’ [-Wformat=]
26
+ ex2_2_1.c:15:10: warning: format 〓〓〓%p〓〓〓 expects argument of type 〓〓〓void *〓〓〓, but argument 2 has type 〓〓〓int〓〓〓 [-Wformat=]
26
- printf("addressofp=%a\n", a);
27
+ printf("address of a =%p\n", p);
28
+ ^
27
29
  ```
28
30
 
29
31
  ###該当のソースコード
@@ -40,9 +42,11 @@
40
42
  int*a;
41
43
  a = &p;
42
44
 
43
- //print address
45
+ //print
46
+ printf("value of a =%d\n", a);
44
- printf("addressofa=%p\n", p);
47
+ printf("address of a =%p\n", p);
48
+ printf("value of p =%d\n", p);
45
- printf("addressofp=%a\n", a);
49
+ printf("address of p=%p\n", a);
46
50
  return 0;
47
51
  }
48
52