Program of swapping in c++, C/C++ Programming

Program of swapping two varibales:

void swap(int *, int *);   // This is swap's prototype

int main()

{

                int x = 5, y = 7;

                swap(&x, &y);

                cout << "\n x is now "<< x << " and y is now " << y << '\n';

 

                return 0;

}

void swap(int *a, int *b)    // swap is actually defined here

{

                int temp;

                temp = *a;

                *a = *b;

                *b = temp;

}

Posted Date: 10/18/2012 9:25:02 AM | Location : United States







Related Discussions:- Program of swapping in c++, Assignment Help, Ask Question on Program of swapping in c++, Get Answer, Expert's Help, Program of swapping in c++ Discussions

Write discussion on Program of swapping in c++
Your posts are moderated
Related Questions
C Program for CREATE MATRICES #include stdio.h> #include conio.h> void main() {           int a[10][10],rw=0,clm=0,i=0,j=0;           char s=' ';           c

Program is to find the area of room: Program is to find the area of room with default values using classes & object class room   {   private:     int len;     i

Differences between a pointer and a reference 1.  A reference must always point to some object where as this restriction is not imposed on a pointer. e.g. int *pi = 0;

Create a mathematical number guessing game. Have the user prompt for the number of games that they want to play. Then each game consists of the following rules. a. The computer

write a function named "fact"that takes one integer arguments,call them "num" and returns as ..............


Write a program to define a matrix: 1. Write a function that takes an integer and calculates and returns the factorial of the integer. The Factorial of a number "n" is compute

: Write a program that prompts the user to enter five digit positive numbers. The program then outputs the digits of the number one digit per line. Eg if the user enters 32456, th


Write a C++ program which does the following: 1. Asks the user to enter the following text "Four score and seven years ago there was a man named Joey Bagadonuts." 2. Save thi