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
How do pointers work?
Keyword mean in declaration?
What are the benefits of c++?
What is the difference between *p++ and (*p)++ ?
Evaluate !(1&&1||1&&0) a) Error b) False c) True
What is the difference between an external iterator and an internal iterator? Describe an advantage of an external iterator?
Does c++ have finally?
What are the various storage classes in C++?
What are the uses of typedef in a program?
Explain what happens when a pointer is deleted twice?
What are the various access specifiers in c++?
Does there exist any way to make the command line arguments available to other functions without passing them as arguments to the function?
What are static variables?
What do you mean by inheritance in c++? Explain its types.
Can class objects be passed as function arguments?