Announcement:

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

Thursday 24 October 2013

[C Program] to Implement Pointer to Function

//Program to implement pointer to function

#include<stdio.h>
#include<conio.h>

void copy(int arr[],int b)
{
int i;
for(i=0;i<b;i++)
{
if(i%2==0)
arr[i]=0;
}
}
void main()
{
int j,a[10],n;
void(*ptr)(int[],int);
clrscr();
ptr=&copy;
printf("Enter the size of an array:");
scanf("%d",&n);
printf("\n\nEnter %d elements into array:",n);
for(j=0;j<n;j++)
{
scanf("%d",&a[j]);
}
printf("\n\nEntered array: ");
for(j=0;j<n;j++)
{
printf("%d\t",a[j]);
}
ptr(a,n);
printf("\n\nUpdated array:  ");
for(j=0;j<n;j++)
{
printf("%d\t",a[j]);
}
getch();
}

/*Output of Program

Enter the size of an array:5
                                                                     
Enter 5 elements into array:12 23 34 45 67                                    
                                                                               
Entered array: 12       23      34      45      67                            
                                                                               
Updated array:  0       23      0       45      0 */
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