What is the use of %p in C

What is %p in C Programming ?

%p is a format specifier in C Programming language, that is used to work with pointers while writing a code in C.
What is the use of %p in C

How to use %p in C Programming?

Lets see an example and understand the working of %p format specifier in C programming language –

Example:

Run
// %p prints the address in hexadecimal format 
#include <stdio.h>

int main() 
{
    int var = 10;
    
    // declaring pointer variable to store address of var
    int *ptr = &var; 

    printf("The address in decimal : %d \n", ptr); 
    printf("The address in hexadecimal : %p \n", ptr); 

    return 0; 
}

Output:

The address in decimal : 1044715932 
The address in hexadecimal : 0x7fff3e45199c 

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription