this is to swap to strings....but in output the whole
strings are swapped leaving first as it is...why it is so

#include<iostream.h>
int main()
{
char a[]="ajeet";
char b[]="singh";
long x=*a;
long y=*b;
cout<<x<<":"<<y;
x=x+y;
y=x-y;
x=x-y;
*a=x;
*b=y;
cout<<x<<":"<<y;
cout<<&a<<endl;
cout<<&b<<endl;
}



this is to swap to strings....but in output the whole strings are swapped leaving first as it is.....

Answer / sachin chakote

only first letter will be swapped

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ General Interview Questions

What is stoi in c++?

0 Answers  


What are the differences between a struct in C and in C++?

8 Answers   Amazon, Wipro,


What is the default width for ouputting a long integer using the insertion operator?

0 Answers  


Write a note about the virtual member function?

0 Answers  


A prime number is a number which is divisible only by itself and 1. Examples of the first few primes are 2, 3, 5, 7, 11. Consider writing a program which can generate prime numbers for you. Your program should read in and set a maximum prime to generate and a minimum number to start with when looking for primes. This program should be able to perform the following tasks: 1. Read the maximum number from user (keyboard input) to look for primes. The program should not return any primes greater than this number. 2. Read the minimum number from user (keyboard input) to look for primes. The program should not return any primes less than this number. 3. Generate and print out every prime number between the maximum prime and minimum number specified by the user.

0 Answers  






Why do we use string in c++?

0 Answers  


Describe the advantage of an external iterator.

0 Answers  


What is the difference between "overloading" and "overridding"?

3 Answers  


How do you sort a sort function in c++ to sort in descending order?

0 Answers  


Does c++ support multilevel and multiple inheritances?

0 Answers  


What is a base class?

0 Answers  


What does obj stand for?

0 Answers  


Categories