新手C求教指导~~~

ohno_123 2018-01-26 06:45:55
#include<stdio.h>
int main(void)
{
char note[] = "See you at the snack bar.";
char * ptr;
ptr = note;
puts(ptr);
puts(++ptr);
note[7] = '\0';
puts(note);
puts(ptr);
puts(++ptr);
return 0;
}
/*
输出:
See you at the snack bar.
ee you at the snack bar.
See you
ee you
e you
请按任意键继续. . .
*/
最后两个不是输出:See you
ee you
哪位大神指点下,谢谢~~~
...全文
598 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
leetow2006 2018-02-05
  • 打赏
  • 举报
回复
puts(++ptr);以后指针移动了
zhagoodwell 2018-02-03
  • 打赏
  • 举报
回复
#include<stdio.h>
int main(void)
{
char note[] = "See you at the snack bar.";
char * ptr;
ptr = note;
puts(ptr);
puts(ptr+1);
note[7] = '\0';
puts(note);
puts(ptr);
puts(++ptr);
return 0;
}
你在开始的时候已经对指针进行更改了。。。
自信男孩 2018-01-27
  • 打赏
  • 举报
回复
这是因为第一个puts(++ptr);此时的ptr已经指向了字符串node的第二个字符,即'e',所以再次puts(ptr)时,应该是从"See"的第一个'e'开始输出;最后一个puts(++ptr);ptr指向了“See"的第二个字符'e',因此输出是"e you" 个人建议通过打印出ptr的地址,这样能更好的分析原因:
#include<stdio.h>

int main(void)
{
    char note[] = "See you at the snack bar.";
    char * ptr;
    printf("0. note: %p\n", note);
    ptr = note;
    printf("1. pstr: %p\n", ptr);
    puts(ptr);

    puts(++ptr);
    printf("2. pstr: %p\n", ptr);
    note[7] = '\0';
    puts(note);
    puts(ptr);
    puts(++ptr);
    printf("3. pstr: %p\n", ptr);
    return 0;
}

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧