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

Assignment Help:

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


Related Discussions:- C program to swap two numbers using reference arguments

Hotel booking, Construct a console program to manage the booking of a Hotel...

Construct a console program to manage the booking of a Hotel room.

Illustrate the problems with multiple inheritance, Problems With Multiple I...

Problems With Multiple Inheritance The following example presents a problem with multiple inheritance. class Aclass  {   public :  void put()

C and Data structure, Implement multiple stacks in a single dimensional arr...

Implement multiple stacks in a single dimensional array using c.

Object irientation, Explain about the strategies of implementation of the s...

Explain about the strategies of implementation of the statecharts, Database Management System?

Explain default arguments, Default Arguments A default argument is a va...

Default Arguments A default argument is a value that is automatically assigned to a formal variable, if the actual argument from the function call is omitted. e.g. void

Subrotine assembly language, You have to write a subroutine (assembly langu...

You have to write a subroutine (assembly language code using NASM) for the following equation.

How can i provide printing for whole hierarchy of classes?, A: Provide a fr...

A: Provide a friend operator class Base { public: friend std::ostream& operator ... protected: virtual void printOn(std::ostream& o) const; }; inline std::ostr

Assignment, Design a black box suit for function whether a character or st...

Design a black box suit for function whether a character or string up to 25 characters

Define bit fields, Define Bit Fields Bit Fields permits the packing of ...

Define Bit Fields Bit Fields permits the packing of data in a structure. This is particularly useful when memory or data storage is at a premium. Usual examples: Packing

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd