再次郁闷下.....C语言

来源:百度知道 编辑:UC知道 时间:2024/06/17 22:21:48
#include <stdio.h>
#include <stdlib.h>
#define max 100
void pcopy(char *p)
{int n,m,i;
printf("input n ang m:");
scanf("%d%d",&n,&m);
printf("\n");
for(i=n;i<=m;i++)
printf("%c",*(p+i));
}
((((((((((((((这里......指针P是指向谁的
for(i=n;i<=m;i++)
printf("%c",*(p+i)); 这两句怎么理解 )))))))))))))))))))))))))))))

int main(int argc, char *argv[])
{char str[max];
printf("please input a string:\n");
gets(str);
pcopy(str);
system("PAUSE");
return 0;
}

主函数里pcopy(str); 把字符数组str[MAX]的首地址作为实参传递给函数pcopy();
所以p是指向str[]的指针,楼主说的那2句的作用就是打印出str[n]到str[m]中间的字符

指针p指向的是那个字符串str的首地址,然后printf("%c",*(p+i));这句是吧str字符串的字符从一次打出来,*(p+i)指向的是str的第i个字符