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
Is ca high or low level language?
What is constructor c++?
What does new in c++ do?
What is void pointer in c++ with example?
What is a storage class?
How a macro differs from a template?
What are punctuators in c++?
Define anonymous class.
What is atoi?
Which software is best for c++ programming?
What is general format for a prototype?
What do you mean by volatile and mutable keywords used in c++?
Write about the role of c++ in the tradeoff of safety vs. Usability?
What does namespace mean in c++?
What is using namespace std in cpp?