Why is a format specifier used? Explain with examples.

A format specifier is used to specify the type of data that should be displayed or processed when using input/output functions like printf() and scanf(). It ensures proper formatting of values. For example, %d is used for integers, %f for floating-point numbers, and %s for strings. Example:

int num = 10;
printf(“The number is %d”, num);

In this example, %d tells the printf() function to print the integer value of num.