Archive
Archive for January 14, 2010
C++ Program to implement Pointer to function – Q14
January 14, 2010
Leave a comment
Q14. Program to implement Pointer to function:
Get the sum of two numbers using the concept of pointer to function.
… from College notes (BCA/MCA assignments):
#include <iostream.h>
#include <conio.h>
int sumNum(int a, int b){
return (a+b);
}
int (*ptr_f)(int, int); // pointer to function.
void main(){
int num1, num2;
clrscr();
cout<<"\n Enter 1st Number: ";
cin>>num1;
cout<<"\n Enter 2nd Number: ";
cin>>num2;
ptr_f = &sumNum; // ptr_f points to display.
cout<<"\n Sum of two Numbers: "<<ptr_f(num1, num2);
getch();
}
Output:
Enter 1st Number: 34
Enter 2nd Number: 45
Sum of two Numbers: 79
Categories: Cpp
Cpp, Pointer to function




