Why does using the wrong format specifier in C crash my program on Windows 7?

前端 未结 5 1573
后悔当初
后悔当初 2020-12-11 14:56

My program is as follows;

#include 
#include 

int main()
{
        char string[] = \"Gentlemen start your engines!\";
                


        
5条回答
  •  情深已故
    2020-12-11 15:34

    Using incorrect format specifier in printf() invokes Undefined Behaviour. Correct format specifier should be %zu (not %d) because the return type of strlen() is size_t

    Note: Length modifier z in %zu represents an integer of length same as size_t

提交回复
热议问题