Switch to full style
C++ code examples
Post a reply

Swap Using Pointers

Thu Nov 13, 2008 2:50 pm

Swapping the variables contents using pointers.
cpp code
#include <stdio.h>

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

main()
{
int x = 15, y = 74;
printf("%d %d\n", x, y);
swap(&x, &y);
printf("%d %d\n", x, y);
}




Post a reply
  Related Posts  to : Swap Using Pointers
 list swap in C++     -  
 swap two numbers c++ program     -  
 SWAP images using JQuery just by using the src attribute img     -  
 Types of Pointers in C++     -  
 How to use pointers and what it means     -  
 Basic Pointers     -  
 Arrays using Pointers     -  
 pointers to derived types     -  
 The using of pointers between two variables (Swaping)     -  
 Passing Pointers to function example     -  

Topic Tags

C++ Variables