用指针逆序输出字符串

知识点:通过指针引用字符串

#include
#include
void nixu(char *str)
{
	char *p = str, *q = str;
	while (*q++);
	q = q - 2;
	while (p <= q)
	{
		putchar(*q--);
	}
}
int main()
{
	char a[20];
	gets_s(a,20);
	nixu(a);
	system("pause");
	return 0;
}

运行结果

用指针逆序输出字符串_第1张图片

 

你可能感兴趣的:(用指针逆序输出字符串)