07-26-2023, 07:11 AM
Mismatching format specifiers with the data types can lead to undefined behavior or incorrect output.
// Incorrect
int x = 10;
printf("Value of x: %s\n", x); // Incorrect format specifier '%s' for integer
// Correct
int x = 10;
printf("Value of x: %d\n", x); // Output: Value of x: 10
// Incorrect
int x = 10;
printf("Value of x: %s\n", x); // Incorrect format specifier '%s' for integer
// Correct
int x = 10;
printf("Value of x: %d\n", x); // Output: Value of x: 10