Yogesh Sharma
2 weeks ago
Yogeshcountry asked

I did not understand how %d works.

Sudip Bhandari
Expert
2 weeks ago

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.