-6

Reverse operations with out temporary variable and in-built functions like string reverse.

sai
  • 11
  • 1
  • 2
  • 1
    `with out temporary variable` actually I don't suppose such solutions exist.. – starrify Apr 14 '14 at 12:02
  • 2
    You should let us know why you have these constraints, or we may suspect we're just doing your homework assignment for you – greggo Apr 14 '14 at 12:03
  • It is not like that , i encountered such a situation where this can give me a solution in my project. – sai Apr 14 '14 at 12:07
  • 1
    Best elaborate what "without temporaries" means exactly. If there is no loophole to exploit, it's probably impossible. – Deduplicator Apr 14 '14 at 12:26

1 Answers1

0

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;
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Khawar Ali
  • 3,462
  • 4
  • 27
  • 55