The difference between printf(str) and printf(str,%s)

The weather will be fine on Monday, February 1, 2021 [Do not lament the past, do not waste the present, do not fear the future]


printf(str): Since it printfsupports variable parameters, the number of subsequent variables needs to be determined by the format string in str. When the strstring contains an %s,%d,%cequal format string, printfit will go to the stack to find the variable corresponding to the format string, but in fact, no printfmore parameters are pushed at all , so printing failure or program crash will occur. As shown in the figure below:
Insert picture description here
Therefore, when writing code, you must not use it printf(str), and use it honestly printf(str,%s).


references

https://blog.csdn.net/readonlyfile/article/details/25222587?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-5.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-5.control

Guess you like

Origin blog.csdn.net/m0_37433111/article/details/113503751