2015-11-02 38 views
-2
#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; 
} 

我找到了一些警告如何以c语言删除格式警告?

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

即使程序运行,因为我打算,我想知道为什么发生这种情况。

我应该怎么做才能删除这些错误而不会在结果中出现错误?

+4

请上传文本格式的代码在这里。 –

+0

@SouravGhosh'UB'是什么意思? – Kotshi

+1

@Kotshi未定义的行为。 –

回答

5

您可以使用指针%p格式为

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

非常感谢! –

+0

演员:'%p'需要'(void *)&var'。 –

+0

有道理。修复了代码。 – user1969104