C printf格式字符串

-5 c printf

在C语言中,以下程序是%5 %%,但我不知道如何?

 printf("%6%5%%%78%");
Run Code Online (Sandbox Code Playgroud)

Min*_*n91 6

这是未定义的行为,并且是特定于编译器/平台的.具有错误参数的Printf函数将开始从堆栈中转换变量,然后任何事情都可能发生.

这就是为什么编译器通常会抱怨这一点

source.c:5:5: warning: conversion lacks type at end of format [-Wformat]
source.c:5:5: warning: conversion lacks type at end of format [-Wformat]
source.c:5:5: warning: conversion lacks type at end of format [-Wformat]
source.c:5:5: warning: spurious trailing '%' in format [-Wformat]
Run Code Online (Sandbox Code Playgroud)

  • @AsdAsd:"任何事情都可能发生,程序形成不良"和"它编译"之间没有矛盾.想一想,只要它需要.这是一个非常重要的观点. (4认同)
  • @Asd:只是因为某些*出现*运行正常,并不意味着它是正确的.如果您将此类问题作为考试问题,您也应该考虑转到更好的学校的课程. (2认同)