c中的垃圾值

Mic*_*ith -8 c

我的代码是

#include<stdio.h>
#include<conio.h>
main()
{
    int p;
    scanf("%d",p);
    printf(p*10);
}
Run Code Online (Sandbox Code Playgroud)

但它给垃圾价值,为什么?

Thi*_*ter 6

您需要&pscanf通话中使用.您还需要在printf()调用中使用格式字符串.

以下是您的代码所包含的主要问题列表:

  • scanf("%d", p) - 你需要将指针传递给int,而不是int.现在,您正在写入未初始化的int变量包含的任何地址/值.
  • printf(p*10) - 您需要将格式字符串作为第一个参数传递,并根据格式字符串将值作为以下参数传递.在您的情况下,"%d"打印一个整数,然后p(或p*10)作为第二个参数.

这是固定代码:

int main()
{
    int p;
    scanf("%d", &p);
    printf("%d\n", p*10);
}
Run Code Online (Sandbox Code Playgroud)