递归逆序打印字符串

    xiaoxiao2025-06-25  5

    #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> void PrintStr(char str[]) { if (NULL == str) return; char *s_p = str; if (*s_p == '\0') //递归退出条件 return; PrintStr(s_p + 1); //此句在上,为逆序打印 printf("%c", *s_p); //PrintStr(s_p + 1); //在下, 为顺序打印 } int main(void) { char a[] = "hello world"; PrintStr(a); system("pause"); return 0; }
    转载请注明原文地址: https://ju.6miu.com/read-1300321.html
    最新回复(0)