tags:

views:

245

answers:

3
#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;
}

This line generates a warning:

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

int format, pointer arg (arg 4)

What is this warning about and how can I resolve it?

+13  A: 

It means that you've used the format of %d (for integer) but the argument is actually a pointer. Use %p instead.

Jon Skeet
+2  A: 

The "%d" conversion specifier expects its corresponding argument to be type int, and you are passing it a pointer to int. Use "%p" to print out pointer values.

John Bode
+1  A: 

As Jon and John said, use %p to print pointer values. %p expects pointer to void (void *), so you will need to cast your pointer in the printf() call to void *. This is because, while in most cases, the compiler does the implicit conversion of any object pointer to void * for you, it doesn't (can't) do that in variadic functions, since it doesn't know that the function needs a void * pointer in those cases.

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