2010-01-15 241 views
1
#include <stdio.h> 

int main() { 
    // Declarations 
    int iCount1, iCount2; 
    int iXXTest[4][3] = {{2, 3, 5}, {9, 8, 6}, {1, 8, 4}, {5, 9, 7}}; 

    // Walk through 1st dimension 
    for (iCount1 = 0; iCount1 < 4; iCount1++) { 
     // Walk through 2nd dimension 
     for (iCount2 = 0; iCount2 < 3; iCount2++) { 
      printf("iXXTest[%d][%d] is at address %d and has a value of %d.\n", iCount1, iCount2, &iXXTest[iCount1][iCount2], iXXTest[iCount1][iCount2]); 
     } 
    } 

    return 0; 
} 

此行生成一个警告:这个C警告是什么意思? “INT格式,指针ARG”

printf("iXXTest[%d][%d] is at address %d and has a value of %d.\n", iCount1, iCount2, &iXXTest[iCount1][iCount2], iXXTest[iCount1][iCount2]); 

INT格式,指针精氨酸(ARG 4)

这是什么警告有关,以及如何能我解决它?

回答

14

这意味着你已经使用%d(用于整数)的格式,但参数实际上是一个指针。改为使用%p。

2

“%d”转换说明符期望其相应的参数是int类型,并且您将它传递给指向int的指针。使用“%p”打印出指针值。

1

正如Jon和John所说,使用%p可以打印指针值。 %p预计指针无效(void *),因此您需要将指针投入printf()调用void *。这是因为,尽管在大多数情况下,编译器会为您执行任何对象指针的隐式转换为void *,但在可变参数函数中不会(不会)这样做,因为它不知道函数需要void *指针在这些情况下。

printf("...at address %p...\n", (void *)&iXXTest[iCount1][iCount2]);