MCPcopy Create free account
hub / github.com/Apress/beginning-cpp20 / main

Function main

Examples/Modules/Chapter 19/Ex19_01/Ex19_01.cpp:7–17  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5long product(long a, long b); // Function prototype
6
7int main()
8{
9 long(*fun_ptr)(long, long) {}; // Pointer to function
10
11 fun_ptr = product;
12 std::cout << "3 * 5 = " << fun_ptr(3, 5) << std::endl; // Call product() thru fun_ptr
13
14 fun_ptr = sum; // Reassign pointer to sum()
15 std::cout << "3 * (4+5) + 6 = " // Call sum() thru fun_ptr twice
16 << fun_ptr(product(3, fun_ptr(4, 5)), 6) << std::endl;
17}
18
19// Function to multiply two values
20long product(long a, long b) { return a * b; }

Callers

nothing calls this directly

Calls 1

productFunction · 0.70

Tested by

no test coverage detected