C program to swap two numbers using reference arguments, C/C++ Programming

Aim: To implement a program to swap two numbers using reference arguments.

Code:

void swap(int *a, int *b)

{

            int temp;

            temp=*a;

            *a=*b;

            *b=temp;

}

void main()

{

            int a,b;

            clrscr();

            cout<<"Program to swap two variables.";

            cout<<"\nEnter variables:\nA:";

            cin>>a;

            cout<<"B:";

            cin>>b;

            swap(&a,&b);

            cout<<"\nSwapped variables:\n\nA:"<

            cout<<"\nB:"<

            getch();

}

Output:

Program to swap two variables.

Enter variables:

A:5

B:36

Swapped variables:

A:36

B:5

Posted Date: 9/29/2012 3:52:27 AM | Location : United States







Related Discussions:- C program to swap two numbers using reference arguments, Assignment Help, Ask Question on C program to swap two numbers using reference arguments, Get Answer, Expert's Help, C program to swap two numbers using reference arguments Discussions

Write discussion on C program to swap two numbers using reference arguments
Your posts are moderated
Related Questions
Question 1 What is function overloading? Write a c++ program to implement a function overloaded Question 2 Explain about the constructors and Destructors with suitable exampl

I really have a hard time analyzing how to write a code in C. It''s all bout Time Departure and we must used a 24 hour clock. Can u help me?

Car Rental System This system tracks cars in a rental company. Each car has a number (assume its plate number), type (small car, four wheel car), and status (rented, available). T

Array types An array is a collection of objects of a one data type. The individual objects are accessed by their position in the array. This way of accessing is known as indexi

Operation Files 2.1. Your program should open and read the file specified by the first command line argument of the program. 2.2. The first line of the file contains an integer

FUNCTIONS It refers to a subprogram that is meant to do a certain task. It is basically used to execute a set of operations and return information to the main or calling functio

Multilevel Inheritance In multilevel inheritance there is a parent class , from whom we derive another class . now from this derived class we can derive another class and so on

#questiowrite a program to calculate e^x

Returning References from Functions Just as in passing the parameters by reference, returning a reference also doesn't return back a copy of the variable , instead an alias is

Inline functions, C++ provides inline functions to help reduce function_call overhead especially for small functions. The qualifier inline before function's return type in the f