dcsimg
Login | Register   
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Intermediate
Jul 26, 2002

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


Swapping Two Pointers (Using Pointers to Pointers)


Sometimes come across a situation where you need to swap two variables. Below is the code that will let you swap two pointers. Say that p and q point to x and y respectively. After swapping them, p and q would point to variables y and x respectively. However, the address of x and y will remain unchanged.
 
void swap(int **p1, int **p2)
{
	int *temp;
	temp = *p1;
	*p1 = *p2;
	*p2 = temp;
}

//Calling syntax is swap(&p,&q);
Mohit Kalra
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date