简体   繁体   English

c指针 - 警告格式'%x'需要'unsigned int'类型的参数

[英]c pointers - warning format '%x' expects arguments of type 'unsigned int'

I'm currently reading Hacking the art of exploitation and there is an example on there that I cannot seem to get correct. 我正在阅读Hacking剥削艺术,有一个例子,我似乎无法正确。 Attempting to compile results in the error: 尝试编译错误的结果:

./addressof.c: In function ‘main’:
./addressof.c:8:4: warning: format ‘%x’ expects argument of type ‘unsigned int’,
but argument 2 has type ‘int *’ [-Wformat]


#include <stdio.h>
int main() {
   int int_var = 5;
   int *int_ptr;

   int_ptr = &int_var; // Put the address of int_var into int_ptr.

   printf("int_ptr = 0x%08x\n", int_ptr);
   printf("&int_ptr = 0x%08x\n", &int_ptr);
   printf("*int_ptr = 0x%08x\n\n", *int_ptr);

   printf("int_var is located at 0x%08x and contains %d\n", &int_var, int_var);
   printf("int_ptr is located at 0x%08x, contains 0x%08x, and points to %d\n\n",
      &int_ptr, int_ptr, *int_ptr);
}

I understand where the error is, I'm just not sure how to fix this. 我理解错误的位置,我只是不确定如何解决这个问题。

The format specifier for pointer is %p , not %x . 指针的格式说明符是%p ,而不是%x (See here ) (见这里

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 警告:格式&#39;%x&#39;需要&#39;unsigned int&#39;类型的参数 - warning: format ‘%x’ expects argument of type ‘unsigned int’ 警告:格式&#39;%lu&#39;期望参数类型为&#39;long unsigned int&#39;,但是参数4的类型类型为&#39;long unsigned int *&#39;[-Wformat] - warning: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'long unsigned int *' [-Wformat] 警告:格式&#39;%c&#39;需要类型&#39;int&#39;,但参数2的类型为&#39;char *&#39; - warning: format '%c' expects type 'int', but argument 2 has type 'char *' 警告:格式“%d”需要“int *”类型的参数,但参数 3 的类型为“uint8_t * {aka unsigned char *} - warning: format ‘%d’ expects argument of type ‘int *’, but argument 3 has type ‘uint8_t * {aka unsigned char *} C 格式“%d”需要“int *”类型的参数,但参数 2 的类型为“无符号整数”[-Wformat=] - C Format '%d' expects argument of type 'int *' but argument 2 has type 'unsigned int' [-Wformat=] C 警告“格式 '%d' 需要类型为 'int *' 的参数,但参数 2 的类型为 'int” - C Warning "format '%d' expects argument of type 'int *', but argument 2 has type 'int" C 语言:收到错误:警告:格式 &#39;%d&#39; 需要类型为 &#39;int *&#39; 的参数,但参数 2 的类型为 &#39;int **&#39; [-Wformat=] - C language: received error: warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘int **’ [-Wformat=] 警告:格式&#39;%llx&#39;期望的参数类型为&#39;long long unsigned int *&#39;,但是参数3的类型为&#39;off64_t *&#39;[-Wformat] - warning: format ‘%llx’ expects argument of type ‘long long unsigned int *’, but argument 3 has type ‘off64_t *’ [-Wformat] 警告:格式&#39;%d&#39;期望类型为&#39;int *&#39;,但是参数2的类型为&#39;int **&#39; - warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int **’ 警告:格式“%d”需要类型“int *”,但参数 2 的类型为“int” - warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int’
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM