C Compiler Logo

Format String Mismatch

Format String Mismatch

warning
warning: format '%d' expects argument of type 'int', but argument has type 'char *'

Description

The format specifier in a printf or scanf function doesn't match the type of the provided argument.

Common Causes

Example of Error

Error Code

int main() {
    char *str = "Hello";
    printf("String: %d\n", str);  // %d is for integers, not strings
    return 0;
}

Solution

Use the correct format specifier for each argument type.

Corrected Code

int main() {
    char *str = "Hello";
    printf("String: %s\n", str);  // %s for strings
    return 0;
}

Additional Tips