1、思维导图
2、使用指针实现两个字符串的比较
#include <stdio.h>
#include <string.h>
int main(int argc, const char *argv[])
{
char str[20] = "hello";
char str1[10] = "hemn";
int i = 0,ret;
char *p=str;
char *p1=str1;
while(p1[i])
{
if(p[i]!=p1[i])
{
ret = p[i]-p1[i];
break;
}
i++;
}
if(p[i]=='\0')
{
ret=p[i]-p1[i];
}
printf("%d\n",ret);
return 0;
}
3、使用指针实现字符串连接
#include <stdio.h>
#include <string.h>
int main(int argc, const char *argv[])
{
char str[20] = "hello ";
char str1[10] = "world";
char *p=str;
char *p1=str1;
int i=0,j=0;
while(p[i])
{
i++;
}
while(p1[j])
{
p[i] = p1[j];
i++;
j++;
if(p1[j]=='\0')
{
p[i] = p1[j];
}
}
puts(p);
return 0;
}
4、用指针实现字符串逆置
#include <stdio.h>
#include <string.h>
int main(int argc, const char *argv[])
{
char str[30] = "";
printf("输入字符:");
gets(str);
int len = strlen(str);
int i = 0;
char *p=str;
char temp;
while(i<len/2)
{
temp = p[i];
p[i] = p[len-1-i];
p[len-1-i] = temp;
i++;
}
printf("逆置结果为:");
puts(p);
return 0;
}
5、通过数组指针二维数组实现杨辉三角
#include<stdio.h>
int main(int argc, const char *argv[])
{
int arr[10][10]={1};
int (*p)[10]=arr;
for(int i=0;i<10;i++)
{
arr[i][0]=arr[0][0];
for(int j=1;j<=i;j++)
{
*(p[i]+j)=*(p[i]+j-1) + *(p[i-1]+j-1);
}
}
for(int i=0;i<10;i++)
{
for(int j=0;j<=i;j++)
{
printf("%-3d",*(p[i]+j));
}
printf("\n");
}
return 0;
}