Announcement:

This is just the beginning of this blog, please don't copy any of my posts.

Thursday 24 October 2013

[C Program] to Pass Pointer to the Function


//Program to pass pointer to the function.
#include<stdio.h>
#include<conio.h>

//Declaring the swap function.
void swap(int *ptr,int *ptr1);

//Main function.
void main()
{
int a,b;
clrscr();
printf("Enter value of a:");
scanf("%d",&a);
printf("\nEnter value of b:");
scanf("%d",&b);
swap(&a,&b);
printf("\nAfter swapping, values of a & b:%d & %d respectively\n",a,b);
getch();
}//end of main

//Definition of swap function.
void swap(int *ptr,int *ptr1)
{
int temp;
temp=*ptr;
*ptr=*ptr1;
*ptr1=temp;
}

/*Output of Program

Enter value of a:67

Enter value of b:89

After swapping, values of a & b:89 & 67 respectively */                                   
Share it Please

Pankaj Gaikar

Pankaj Gaikar is a professional blogger from Pune, India who writes on Technology, Android, Gadgets, social media and latest tech updates at Punk Tech , Being Android & Shake The Tech . Email me HERE

0 comments :

Post a Comment

Copyright @ 2013 Pune University Bachelor of Engineering . Designed by Pankaj Gaikar | Love for The Tricks Machine