[cc150] 1.2

来源:互联网 发布:淘宝上怎么买高仿的包 编辑:程序博客网 时间:2024/06/11 21:53

1.2 Write code to reverse a C-Style String.

class Solution { public:     void reverse(char *str){         if (!*str) return;         char *p = str, *q = str;         while (*q) q++;         q--;         char tmp;         while (p < q) {             tmp = *p;             *p++ = *q;             *q-- = tmp;         }     } }; 

这个题目也木有什么特别的,要注意的一点就是字符串的定义方式。

char *str="hello"是放在代码段中的,不可改变
char str[10]="hello"是放在堆栈中的,可以任意使用,不过要注意地址不要越界哦


原创粉丝点击