如何使用指针和字符在 C 中询问用户输入
#include<stdio.h>
int main(){
char *p;
printf("User:- Please write about my self here --> \n");
scanf("%s",p);
//Case 1
printf("The o/p of first persion is here -->>\n %s",p);
//This gives output as (null) Can you please tell why it's happening
// Case 2
printf("\n The op here is -->> %p\n",p);
//This gives op as (nil)
}
你能向我解释一下吗?或者删除一些指针链接,这是我第一次了解堆栈和指针 提前致谢。参考案例 1、2
#include<stdio.h>
int main(){
char *p;
printf("User:- Please write about my self here --> \n");
scanf("%s",p);
//Case 1
printf("The o/p of first persion is here -->>\n %s",p);
//This gives output as (null) Can you please tell why it's happening
// Case 2
printf("\n The op here is -->> %p\n",p);
//This gives op as (nil)
}
Can you please explain to me or drop some links for pointer it's my first time on Stack and pointers
Thanks in advance.Refer to case 1, 2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它给出 null 因为你没有初始化 p,你没有给它任何指向的地址。你刚刚宣布了它。使用 malloc() 或为其提供另一个 char 数组的地址。
It is giving null because you not initilized p, you not gave it any address to point. You just declared it. Use malloc() or give it the address of another array of char.