代码
int *ptr;
int a=10;
scanf("%d",ptr);
printf("%d",*ptr);
output:-
5 //for scanf
5 //from printf但
int *ptr;
// removing this `int a=10;`
scanf("%d",ptr);
printf("%d",*ptr);
output change :-
5 //for scanf
//blank (nothing from printf)在这里,我试图直接扫描指针的值,所以如何才能扫描到ptr的值?
不带
int a,*ptr;
ptr = &a;是否必须先将另一个变量的地址赋值给ptr,然后再放入(Scanf)值。
发布于 2022-04-20 15:50:49
对你的问题的回答是“是的”,在使用它来做几乎任何事情(不仅仅是存储指针位置)之前,有必要指定一个指针到某个东西。将指针指向所使用的scanf() on变量。你命名为“没有”的代码似乎是你所需要的。
https://stackoverflow.com/questions/71942103
复制相似问题