如何扭转一个字符串,而无需使用内置的和临时变量 [英] How to reverse a string without using in-built and temporary variables
本文介绍了如何扭转一个字符串,而无需使用内置的和临时变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
与出临时变量和内置功能,如字符串反向反向操作。
Reverse operations with out temporary variable and in-built functions like string reverse.
推荐答案
您可以使用XOR逻辑是这样做的:
You can do it using XOR logic like this:
char* rev(char* str)
{
int end= strlen(str)-1;
int start = 0;
while( start<end )
{
str[start] ^= str[end];
str[end] ^= str[start];
str[start]^= str[end];
++start;
--end;
}
return str;
}
这篇关于如何扭转一个字符串,而无需使用内置的和临时变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文