Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4807f42

Browse files
using function pointers (similar to overloading)
1 parent fb729d9 commit 4807f42

File tree

1 file changed

+38
-0
lines changed
  • Learn_CPP_Programming_Deep_Dive/Section 10 Functions/Function_pointers

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
void display()
6+
{
7+
cout<<"It is Friday evening. Weekend is coming!!"<<endl;
8+
}
9+
10+
int max(int a, int b)
11+
{
12+
cout<<"I am in max function"<<endl;
13+
return a > b ? a : b ;
14+
}
15+
16+
int min(int a, int b)
17+
{
18+
cout<<"I am in the min function"<<endl;
19+
return a < b ? a : b ;
20+
}
21+
22+
23+
int main(void)
24+
{
25+
void (*fp) () ; //declaration
26+
fp = display; // initialization
27+
(*fp)(); // usage of the function pointer
28+
29+
30+
int (*fp1)(int, int); // declaration of function pointers returning other than void and that take parameters
31+
fp1 = max; // initialization
32+
(*fp1)(10,5); // usage
33+
34+
fp1 = min;
35+
(*fp1)(10,5); // usage
36+
37+
return 0;
38+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /