how to swap two nubers by using a function with pointers?



how to swap two nubers by using a function with pointers?..

Answer / reshma

void swap(int *a, int *b)
{
int tmp;
tmp=*a;
*a=*b;
*b=tmp;
}

or

void swap(int *a, int *b)
{
*a=*a^*b;
*b=*a^*b;
*a=*a^*b;

}

Is This Answer Correct ?    10 Yes 1 No

Post New Answer

More C Interview Questions

How pointer is benefit for design a data structure algorithm?

2 Answers  


which is the best antivirus and how to update it

7 Answers   Infosys,


What is the difference between if else and switchstatement

1 Answers  


What is the difference between pure virtual function and virtual function?

1 Answers  


How to print all the 26 alphabets in this order in C. AbCdEfGh..... it should print dynamically from a to z and do not print this using pgm like this print("Ab......"); Use loops or anything to print all alphabets

2 Answers   Hexaware,


In which area global, external variables are stored?

3 Answers  


write a program in c to print **** * * * * ****

1 Answers   TCS,


In cryptography, you could often break the algorithm if you know what was the original (plain) text that was encoded into the current ciphertext. This is called the plain text attack. In this simple problem, we illustrate the plain text attack on a simple substitution cipher encryption, where you know each letter has been substituted with a different letter from the alphabet but you don’t know what that letter is. You are given the cipherText as the input string to the function getwordSets(). You know that a plain text "AMMUNITION" occurs somewhere in this cipher text. Now, you have to find out which sets of characters corresponds to the encrypted form of the "AMMUNITION". You can assume that the encryption follows simple substitution only. [Hint: You could use the pattern in the "AMMUNITION" like MM occurring twice together to identify this]

1 Answers   Infosys,


CAN WE DEFINE ANY FUNCTION WITHIN A FUNCTION.

15 Answers  


program for swapping two strings by using pointers in c language

1 Answers  


Which is better malloc or calloc?

1 Answers  


How can I get random integers in a certain range?

1 Answers  


Categories