How do I print out the address a pointer is holding. Currently I'm using the code pasted below. But I'm getting this error.

Error:
t.c:13:2: warning: format ‘%u’ expects argument of type ‘unsigned int’, but argument 2 has type ‘char *’ [-Wformat]

Code:

#include<stdio.h>
#include<malloc.h>
#include<string.h>
#include<stdlib.h>

char* str;

int main(void)
{
 str = (char*)malloc(200 * sizeof(char));

 strcpy(str,"This is a test");
 printf("\nAddress = %u",str);

 return 0;
}

use %p instead of %u

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.