首页 > 解决方案 > 为什么将输入提供给指针时无法打印值输出?

问题描述

int value = 0;

int *pvalue = &value;

printf("input an integer:");

scanf("%d\n",*pvalue);

printf("you have entered %d\n",value);// this line is not printing in the output

return 0;

我的输出是:

input an integer:5

代码中的另一个printf未打印在输出中。

  1. 我试图调试,但它给出了分段错误。
  2. 我想给指针赋值并获取数据

请任何人告诉我如何将输入的输入作为 printf 中的输出

标签: cpointersinputoutput

解决方案


to 的参数scanf()应该是指针本身,而不是取消引用的指针。

*pvalue与 相同value,即0,因此scanf()尝试将输出写入0( NULL),这是一个无效位置。


推荐阅读