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"); }