0d: 00h: 00m: 00s

🎁 Get 3 extra months of learning — completely FREE

That's 90 extra days to master new skills, build more projects, and land your dream job.

Become a PRO
Background Image

🎁 Get 3 extra months of learning completely FREE

Become a PRO
Yogesh Sharma
last year
Yogeshcountry asked

I did not understand how %d works.

Sudip Bhandari
Expert
last year

In C, %d is a format specifier used to print integer values. It tells printf(), "Insert an integer here."

For example:

#include 

int main() {

    // Declare and assign an int variable
    int age = 25;

    // Print the value of the variable
    printf("John's age is %d", age);

    return 0;
}

Output

John's age is 25

In printf("John's age is %d", age);, the %d is replaced by the value of age, formatting the output correctly.

You'll come across more format specifiers as you progress in the course.

Let me know if anything is unclear. I'm happy to help.

C
This question was asked as part of the Learn C Programming course.