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

Write a C/C++ program to add a user to MySQL. The user should be permitted to only "INSERT" into the given database.

0 Answers   Wipro,


fun(int x) { if(x > 0) fun(x/2); printf("%d", x); } above function is called as: fun(10); what will it print? }

17 Answers   NDS,


i want to have a program to read a string and print the frequency of each character and it should work in turbo c

3 Answers   Persistent, Wipro,


What does sizeof int return?

0 Answers  


Explain how can you tell whether two strings are the same?

0 Answers  






a c variable cannot start with a) an alphabet b) a number c) a special symbol d) both b and c above

0 Answers  


#include<stdio.h> main() { int a[3]; int *I; a[0]=100;a[1]=200;a[2]=300; I=a; Printf(“%d\n”, ++*I); Printf(“%d\n”, *++I); Printf(“%d\n”, (*I)--); Printf(“%d\n”, *I); } what is the o/p a. 101,200,200,199 b. 200,201,201,100 c. 101,200,199,199 d. 200,300

4 Answers   Tieto,


Explain how do you determine the length of a string value that was stored in a variable?

0 Answers  


What is the purpose of scanf() and printf() functions?

0 Answers  


What are the primitive data types in c?

0 Answers  


1 232 34543 4567654 can anyone tell me how to slove this c question

6 Answers  


There are N egg baskets and the number of eggs in each basket is a known quantity. Two players take turns to remove these eggs from the baskets. On each turn, a player must remove at least one egg, and may remove any number of eggs provided they all belong to the same basket. The player picking the last egg(s) wins the game. If you are allowed to decide who is going to start first, what mathematical function would you use to decide so that you end up on the winning side?

8 Answers   Google,


Categories