Write a program to swap 2 chars without using a third
varable?
char *s = "A";
char *p = "B";
Answer Posted / dooglus
#include <cstdio>
void swap(char *c, char *d)
{
*d = *c^*d; // c = C d = C^D
*c = *c^*d; // c = C^C^D d = C^D
*d = *c^*d; // c = C^C^D d = C^C^D^C^D
}
main()
{
char c = 'c';
char d = 'd';
swap(&c, &d);
}
| Is This Answer Correct ? | 20 Yes | 3 No |
Post New Answer View All Answers
What does count ++ do in c++?
What is flush () in c++?
Can I have a reference as a data member of a class? If yes, then how do I initialise it?
Define namespace in c++?
what is a class? Explain with an example.
What are the differences between java and c++?
Can we use pointers in c++?
What are destructors?
How to access a variable of the structure?
What are pointer-to-members in C++? Give their syntax.
Why is null pointer used?
Which is the best c++ software?
How do I download c++?
What is c++ array?
Is there a sort function in c++?