main(){ char *ps="this is a book"; int n=10; ps=ps+n; printf("%s/n",ps); }
运行结果为:
book 在程序中对ps初始化时,即把字符串首地址赋予ps,当ps= ps+10之后,ps指向字符“b”,因此输出为"book"。
main(){ char st[20],*ps; int i; printf("input a string:/n"); ps=st; scanf("%s",ps); for(i=0;ps[i]!='/0';i++) if(ps[i]=='k'){ printf("there is a 'k' in the string/n"); break; } if(ps[i]=='/0') printf("There is no 'k' in the string/n"); }