-6

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

4
  • 1
    with out temporary variable actually I don't suppose such solutions exist.. Commented Apr 14, 2014 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 Commented Apr 14, 2014 at 12:03
  • It is not like that , i encountered such a situation where this can give me a solution in my project. Commented Apr 14, 2014 at 12:07
  • 1
    Best elaborate what "without temporaries" means exactly. If there is no loophole to exploit, it's probably impossible. Commented Apr 14, 2014 at 12:26

1 Answer 1

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;
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.