Pages

Thursday, 31 August 2017

CBSE Class 10 - C++ Practical Pointer Handling Snippet-12 Swap Integers Using Pointers (#cbseNotes)

C++ Practical
Pointer Handling Snippet-12
Swap Integers Using Pointers 

CBSE Class 10 - C++ Practical Pointer Handling Snippet-12 Swap Integers Using Pointers (#cbseNotes)


Question: Write a function using pointers to swap two integers. *


Answer:




// Question: Write a program using pointers to swap two integers. *

#include <iostream.h>
#include <conio.h>

void swap_using_pointers(int *, int *);

void main()
{
 clrscr();
 int a,b;
 cout<<"\n\nEnter first  integer : "; 
 cin >> a;
 
 cout<<"\n\nEnter second integer : "; cin>>b;
 
 swap_using_pointers(&a,&b);
 
 cout<<"\n\nNow value of first  integer = "<<a;
 cout<<"\n\nNow value of second integer = "<<b;
 getch();
}

void swap_using_pointers(int *a,int *b)
{
 int temp;
 temp=*a;
 *a=*b;
 *b=temp;
}


Program Output:

CBSE Class 10 - C++ Practical Pointer Handling Snippet-12 Swap Integers Using Pointers (#cbseNotes)


No comments:

Post a Comment

We love to hear your thoughts about this post!

Note: only a member of this blog may post a comment.