printf返回32676。请让我理解为什么以下的输出不是11

时间:2017-10-05 15:28:40

标签: c printf

    #include<stdio.h>
    void main()
    {
    int a,b,p;
    printf("Enter values of a and b");
    scanf("%d%d", &a, &b);
    p=printf("a=%d b=%d p=%d",a,b, p);
    }

这是我的问题的代码。将输入视为a = 2和b = 3.

1 个答案:

答案 0 :(得分:3)

变化:

p=printf("a=% b=%d p=%d",a,b, p);

为:

p = printf("a=%d b=%d\n", a, b); // <<< fix format string
printf("p=%d\n", p);             // <<< print `p` *after* you have assigned a value to it

请从今天开始启用编译器警告 - 任何优秀的编译器都会在编译时向您指出所有上述错误。