format specifies type 'unsigned int' but the argument has type 'int *' [-Wformat] solution

There will be a warning to compile this program with a clang:format specifies type 'unsigned int' but the argument has type 'int *' [-Wformat]

After the binaries compiled execution, achieving the desired result.

#include <stdio.h> 
 
const int = MAX. 3; 
 
int main () 
{ 
   int var [] = {10, 100, 200 is}; 
   int I, * PTR; 
 
   / * pointer to an address array * / 
   PTR = var; 
   for (I = 0; I <MAX; I ++) 
   { 
 
      the printf ( "memory address: var [% D] =% X \ n-", I, PTR); 
      the printf ( "stored values: var [% d] =% d \ n-", I, * PTR); 
 
      / * move to the next position * / 
      PTR ++; 
   } 
   return 0; 
}

Solution is as follows:

     / * Ptr read: (unsigned int) ptr * /
#include <stdio.h> 
 
const int = MAX. 3; 
 
int main () 
{ 
   int var [] = {10, 100, 200 is}; 
   int I, * PTR; 
   / * pointer to an address array * / 
   PTR = var; 
   for (I = 0; I <MAX; I ++) 
   { 

     / * PTR to: (unsigned int) PTR * / 
      the printf ( "memory address: var [% d] =% x \ n", i, (unsigned int) PTR); 


      the printf ( "stored values: var [D%] D =% \ n-", I, * PTR); 
      / * move to the next position * / 
      PTR ++; 
   } 
   return 0; 
}

 

Released eight original articles · won praise 3 · Views 889

Guess you like

Origin blog.csdn.net/weixin_42934172/article/details/97617207