QP School

Full Version: Using incorrect format specifiers in C
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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