+2 votes
in Programming Languages by (72.8k points)
I found on a C tutorial website that they are using %x to print the address contained in a pointer. When I am trying to do the same thing, I am getting warning "Warning : format ‘%x’ expects argument of type ‘unsigned int’, but argument 2 has type ‘int *’". How can I fix the warning message?

1 Answer

+1 vote
by (355k points)
selected by
 
Best answer

From the warning message, you can understand that it was expecting "unsigned int" instead of "int *". To print the address contained in a pointer, use "%p". The website is either ignoring warning message or using some old compiler. If you are using GCC, use "%p" to get rid of the warning message.

int main(){

        int *ip;

        int b=20;

        ip=&b;

        printf("address of b is %p",ip);

        return 0;

}


...