Here is
main()
. Notice that
findmax()
is applied to different-sized dynamically allocated structures.
#include <iostream.h>
int main(){
twod a, b;
int i, j;
// ----- function call
allocate(2, 3, a);
allocate(4, 6, b);
for (i = 0; i < a.column_size; ++i)
for (j = 0; j < a.row_size; ++j)
a.base[i][j] = i * j ;
for (i = 0; i < b.column_size; ++i)
for (j = 0; j < b.row_size; ++j)
b.base[i][j] = i * j ;
cout << findmax(a) <<
" max in size 2 * 3 " << endl;
cout << findmax(b) <<
" max in size 4 * 6 " << endl;
}
int main()
This is called the
function header, which identifies the function. Here, int is a type name that defines the type of value that the main() function returns when it finishes execution, namely an integer. In general, the parentheses following a name in a function definition enclose the specification for information to be passed to the function when you call it. There is nothing between the parentheses in this instance but there could be.
You will learn how you specify the type of information to be passed to a function when it is executed.
I will always put parentheses after a function name in the text to distinguish it from other things that are code. The executable code for a function is always enclosed between braces and the opening brace follows the function header.