質問編集履歴
1
コードの修正
    
        title	
    CHANGED
    
    | 
         
            File without changes
         
     | 
    
        body	
    CHANGED
    
    | 
         @@ -2,28 +2,30 @@ 
     | 
|
| 
       2 
2 
     | 
    
         
             
            C言語で2つのポインタでデータとアドレスを表示するというコードを書いています。イメージの図は以下の様です。
         
     | 
| 
       3 
3 
     | 
    
         
             
            
         
     | 
| 
       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  
     | 
| 
      
 10 
     | 
    
         
            +
            ex2_2_1.c: In function 〓〓〓main〓〓〓:
         
     | 
| 
       10 
     | 
    
         
            -
            ex2_2_1.c:9:7: error: conflicting types for  
     | 
| 
      
 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  
     | 
| 
      
 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  
     | 
| 
      
 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  
     | 
| 
      
 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  
     | 
| 
      
 23 
     | 
    
         
            +
            ex2_2_1.c:14:10: warning: format 〓〓〓%d〓〓〓 expects argument of type 〓〓〓int〓〓〓, but argument 2 has type 〓〓〓int *〓〓〓 [-Wformat=]
         
     | 
| 
       23 
     | 
    
         
            -
               printf(" 
     | 
| 
      
 24 
     | 
    
         
            +
               printf("value of a =%d\n", a);
         
     | 
| 
       24 
25 
     | 
    
         
             
                      ^
         
     | 
| 
       25 
     | 
    
         
            -
            ex2_2_1.c:15:10: warning: format  
     | 
| 
      
 26 
     | 
    
         
            +
            ex2_2_1.c:15:10: warning: format 〓〓〓%p〓〓〓 expects argument of type 〓〓〓void *〓〓〓, but argument 2 has type 〓〓〓int〓〓〓 [-Wformat=]
         
     | 
| 
       26 
     | 
    
         
            -
               printf(" 
     | 
| 
      
 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 
     | 
| 
      
 45 
     | 
    
         
            +
              //print                                                                       
         
     | 
| 
      
 46 
     | 
    
         
            +
              printf("value of a =%d\n", a);
         
     | 
| 
       44 
     | 
    
         
            -
              printf(" 
     | 
| 
      
 47 
     | 
    
         
            +
              printf("address of a =%p\n", p);
         
     | 
| 
      
 48 
     | 
    
         
            +
              printf("value of p =%d\n", p);
         
     | 
| 
       45 
     | 
    
         
            -
              printf(" 
     | 
| 
      
 49 
     | 
    
         
            +
              printf("address of p=%p\n", a);
         
     | 
| 
       46 
50 
     | 
    
         
             
              return 0;
         
     | 
| 
       47 
51 
     | 
    
         
             
            }
         
     | 
| 
       48 
52 
     | 
    
         |