c - 为什么将输入提供给指针时无法打印值输出?
问题描述
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
未打印在输出中。
- 我试图调试,但它给出了分段错误。
- 我想给指针赋值并获取数据
请任何人告诉我如何将输入的输入作为 printf 中的输出
解决方案
to 的参数scanf()
应该是指针本身,而不是取消引用的指针。
*pvalue
与 相同value
,即0
,因此scanf()
尝试将输出写入0
( NULL
),这是一个无效位置。
推荐阅读
- tensorflow - Cloud TPU 工具未生成配置文件
- laravel - socket.io vs pusher,哪个更适合与 laravel 一起使用
- javascript - 将数组值插入特定的表格单元格/列
- python - 使用 for 循环生成多个按钮,并能够区分它们并在鼠标单击时运行单独的代码。
- javascript - Nuxt Vue2 应用,添加 Vue-Touch 包
- html - SVG填充悬停时的文本更改
- javascript - 我如何能够针对特定的表来操作它?
- tcl - 向 TCL 列表的元素添加额外的反斜杠
- excel - 如何从字符串中提取文本 - Excel
- csv - SSIS 包创建 .csv 文件,添加列但不添加行