Function using pointers

 Function using pointers: pointers are very useful in the function and we send the addresses instead of values because the pointers are works with the addresses.

Program:

PROGRAM TO SWAP TWO NUMBRES USING POINTERS

#include<stdio.h>

#include<conio.h>

void swap(int *, int *);

void main()

{

int a,b;

clrscr();

printf(“Enter any two numbers: “);

scanf(“%d%d”,&a,&b);

printf(“Before swapping numbers are: a=%d, b=%d\n”,a,b);

swap(&a,&b);

printf(“After swapping numbers are: a=%d, b=%d”,a,b);

getch();

}

void swap(int *a,int *b)

{

int temp;

temp=*a;

*a=*b;

*b=temp;

}

Posted in C

Leave a Reply

Your email address will not be published. Required fields are marked *