Geeks Talk

Prepare for your Next Interview


Welcome to the Geeks Talk forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

funtion swap

This is a discussion on funtion swap within the C and C++ forums, part of the Software Development category; How do you write a function swap?...

Go Back   Geeks Talk > Software Development > C and C++
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read
  #1 (permalink)  
Old 04-27-2008
Junior Member
 
Join Date: Apr 2008
Posts: 3
Thanks: 0
Thanked 1 Time in 1 Post
Twanawiliams is on a distinguished road
funtion swap

How do you write a function swap?
Reply With Quote
The Following User Says Thank You to Twanawiliams For This Useful Post:
Sponsored Links
  #2 (permalink)  
Old 05-05-2008
Junior Member
 
Join Date: May 2008
Location: Raipur
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
sweta rajkotia is on a distinguished road
Re: funtion swap

you can use follwing code:
#include<stdio.h>
#include<conio.h>
void swap(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
printf("a=%d b=%d",*a,*b);
}
void main()
{
int a=5,b=8;
swap(&a,&b);
}
Reply With Quote
  #3 (permalink)  
Old 2 Weeks Ago
Junior Member
 
Join Date: Feb 2008
Location: India
Posts: 4
Thanks: 1
Thanked 3 Times in 1 Post
iammilind is on a distinguished road
Re: funtion swap

Well, Swetha's method is proper, but only meant for integers.
Following is the swap function for any type like: int, char, structure, pointers etc. anything.

template<class T>
void swap(T &data1, T &data2)
{
T temp = data1;
data1 = data2;
data2 = temp;
}
Reply With Quote
Reply

  Geeks Talk > Software Development > C and C++

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads

Thread Thread Starter Forum Replies Last Post
Swap two numbers Manojks Brainteasers 11 07-15-2009 12:22 PM
Function Swap Twanawiliams C and C++ 2 05-16-2008 04:14 AM
Get output as swap Geek_Guest C and C++ 1 11-19-2007 11:41 AM


All times are GMT -4. The time now is 05:09 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved