Wrong number of parameters to printf leads to strange results

后端 未结 4 1770
臣服心动
臣服心动 2021-01-27 01:26
#include 

int main() {
   int i=10,j=20;
   printf(\"%d%d%d\",i,j);
   printf(\"%d\",i,j); 
   return 0;
}

Using the Turbo C compiler,

4条回答
  •  甜味超标
    2021-01-27 01:57

    You've got your format specifiers all mixed up, and I don't think the code you posted is your actual code. On my Visual Studio compiler, I see this:

    1020010
    

    Each %d denotes a place where printf should insert one of your integer values.

    printf("%d%d%d",i,j);
    

    You told printf to expect three, but you only gave it two. It's possible Turbo C is doing something different with the arguments under the hood, but you still need to match your format specifiers to your arguments:

    printf("%d%d",i,j);
    

提交回复
热议问题