Answer to Question #43023 in C++ for Syed Talha Shah

Question #43023
Write a program to make the pointer to the function for swapping two integers.
1
Expert's answer
2014-06-02T14:29:56-0400
/* Answer on Question#43023 - Subject - Programming, C++ */
#include <stdio.h>
#include <stdlib.h>
void (*p) ( int, int ); /* pointer to function */
void swap( int x, int y) /* swapping two integer function */
{
int temp = y; /*temp var*/
y = x; /* swapping */
x = temp;
printf("Integers after awapping...\nx= %d\ny= %d\n",x,y);
}
int main() /* main function*/
{
int x,y;
printf("x= "); /* user's input of integers */
scanf("%d",&x);
printf("y= ");
scanf("%d",&y);
p = &swap; /* pointer to swap */
p(x,y); /* call the function */
system("pause");
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS