Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

How do pointers work?

1140


Keyword mean in declaration?

1013


What are the benefits of c++?

997


What is the difference between *p++ and (*p)++ ?

1306


Evaluate !(1&&1||1&&0) a) Error b) False c) True

1166


What is the difference between an external iterator and an internal iterator? Describe an advantage of an external iterator?

1074


Does c++ have finally?

976


What are the various storage classes in C++?

1106


What are the uses of typedef in a program?

1048


Explain what happens when a pointer is deleted twice?

1206


What are the various access specifiers in c++?

991


Does there exist any way to make the command line arguments available to other functions without passing them as arguments to the function?

1216


What are static variables?

1095


What do you mean by inheritance in c++? Explain its types.

1078


Can class objects be passed as function arguments?

1019