%p Format Specifier in C

This tutorial will discuss the %p format specifier in C.

the %p Format Specifier in C

The %p format specifier is used for printing the value of a pointer in C. This phenomenon is showed clearly in the coding example below.

#include<stdio.h>

void main() 
{
    int i=100;
    printf("%d\n",i);
    int *pointer = &i;
    printf("%p\n",i);
    printf("%p",pointer);
}

Output:

100
0000000000000064
000000000062FE14

In the above code, we first initialize the integer variable i with int i=100; and print the integer value of i, which is 100. Then we created the pointer pointer that points towards the address of i.

In the next line, we printed the pointer value of i with the %p format specifier inside the print() function. The pointer value of i is 0000000000000064 because 100 becomes 64 in hexadecimal. After that, we printed the value inside the pointer with the %p format specifier.

Contribute
DelftStack is a collective effort contributed by software geeks like you. If you like the article and would like to contribute to DelftStack by writing paid articles, you can check the write for us page.