[英]what is relation of "int a=5" with scanf("%d",ptr) if [ "int* ptr"] ptr is pointer?
code代码
int *ptr;
int a=10;
scanf("%d",ptr);
printf("%d",*ptr);
output:-
5 //for scanf
5 //from printf
but但
int *ptr;
// removing this `int a=10;`
scanf("%d",ptr);
printf("%d",*ptr);
output change :-
5 //for scanf
//blank (nothing from printf)
and here I was trying to scanf value to pointer directly so how can I scanf value to ptr在这里,我试图直接将 scanf 值指向指针,所以如何将 scanf 值指向 ptr
without没有
int a,*ptr;
ptr = &a;
is it compulsory to assign the address of another variable to ptr before putting(scanf) value in it在将(scanf)值放入其中之前是否必须将另一个变量的地址分配给ptr
The answer to your question is "yes," it's necessary to assign a pointer to something before using it for pretty much anything (other than merely storing the pointer location).你的问题的答案是“是的”,在将它用于几乎任何事情之前,有必要为它分配一个指针(除了仅仅存储指针位置)。 Point your pointer to the variable you use scanf() on.
将您的指针指向您使用 scanf() 的变量。 The code you titled "without" seems to be what you need.
您标题为“无”的代码似乎是您所需要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.