I'm trying to learn how to use the pointer in a C program; my example is as follows:
#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { int * tab = (int*)malloc(sizeof(int)*5); int a = 10; int *p; p = &a; printf("the address of a is %d \n",&a); printf("the address of a using the pointer is %p \n",p); printf("the address of tab is %d \n",tab); } I'm trying to print the address of a, the address value inside of p and where the first byte of the tab begins.
I can get hexadecimal values when using "%p", but I'm willing the decimal value of the addresses.
Edit : On this Video image, someone has used "%d" to print a decimal value for a pointer address, and it has confused me.
"%d"works withint. It may not work with&a. Suggestprintf("%p\n",(void*) &a);%p. Forget the decimal interpretation of pointers, the hexadecimal representation is far superior.%pis implementation defined, but it is defined. You code gave decimal output, but not necessarily correct output. Your goal seems to wants any simple decimal output and not necessarily correct decimal output.