c - 如何消除c语言中的格式警告?

标签 c pointers

#include <stdio.h> 
int main(void) { 
  int *pVar, var = 10;
  pVar = &var;
  //*pVar = var; 

  printf("value = %d, address = Ox%X\n", var, &var);    
  // Format specifies type 'unsigned int' but the argument has type 'int *' 
  
  printf("pValue = %d, address = Ox%X\n", *pVar, pVar);
  // Format specifies type 'unsigned int' but the argument has type 'int *' 

  *pVar = 20; 

  printf("value = %d, address = Ox%X\n", var, &var);
  // Format specifies type 'unsigned int' but the argument has type 'int *' 

  printf("pValue = %d, address = Ox%X\n", *pVar, pVar);
  // Format specifies type 'unsigned int' but the argument has type 'int *' 

  return 0; 
} 

我发现一些警告

格式指定类型 unsigned int 但参数类型为 int *

Even though the program runs as I intend, I want to know why this happen.

What should I do to remove those errors without making some errors in result?

最佳答案

您可以使用 %p 格式作为指针,如下

printf("value = %d, address = %p\n", var, (void *) &var);

关于c - 如何消除c语言中的格式警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33471513/

相关文章:

c - Linux fork() 命令

c - 如何关闭在外部函数中打开的文件

c - "Enter a character to quit"C 程序

C程序打印自己的地址空间?

c - 求char**形式的字符串数组的长度?

c - 使用字符指针将文本文件逐行存储到字符数组中

c - 输出文件描述符重定向到管道的进程正在屏幕而不是管道上写入

c++ - 缺少对指向成员函数的绑定(bind)指针的调用

c - 如何对动态分配的数据进行 const 限定?

pointers - 通过传递指针更改 slice