#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/