I had a quick look through that page and it looked a good description, but I wasn't that interested :-)
Let me fire up the Linux box now ...
renniej@H39FC72:~$ ./airport
Default time between the planes arriving is 10 minutes
Enter the new time in minutes or press return to accept the default
Default time for RANDOMNESS is +/- 15 minutes
Enter the new time in minutes or press return to accept the default
Default number of refuelling bays is 12 .
Enter the new value for no of refuelling bays or press return to accept the default
Default time for TURAROUND INTERVAL is +/- 60 minutes
Enter the new time in minutes for Turnaround interval or press return to accept the default
(I removed the flight listing as it didn't seem to add anything)
D:\rhs\c>cl rat2.c
Microsoft (R) C/C++ Optimizing Compiler Version 19.25.28614 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
rat2.c
rat2.c(9): warning C4477: 'printf' : format string '%s' requires an argument of type 'char *', but variadic argument 1 has type 'char (**)[7]'
&b[1] has type pointer to pointer, and a pointer has 4 bytes (because it's a 32 bit address). So when you subtract 3 from &b[1] you are subtracting 3 pointers i.e. 12 bytes.
The array b is stored in memory as 16 bytes i.e. four pointers of four bytes each. Suppose the address of the first byte of memory that stores b is 200, then the 16 bytes of memory would contain:
What cl pointer.c does is to take the code in pointer.c and compile it to produce the executable file pointer.exe. Then to run the program type pointer - Windows assumes you mean pointer.exe so you don't have to type the .exe (though you can if you want).
#include <stdio.h>
/* Example function that just doubles its argument */
int bar(int i)
{
return 2*i;
}
/* foo takes the function it is passed and applies it to the integer
and returns the result */
int foo(int i, int (*bar)(int))
{
return bar(i);
}
int main()
{
printf("foo(2) returned %d\n", foo(2, bar));
}
#include <stdio.h>
/* Example function that just doubles its argument */
int bar(int i)
{
return 2*i;
}
/* foo takes the function it is passed and applies it to the integer
and returns the result */
int foo(int i, int (*bar)(int))
{
return (***bar)(i);
}
int main()
{
printf("foo(2) returned %d\n", foo(2, bar));
}
I wonder how you declare an array of functions ...
/* Example function that doubles its argument */
int bar0(int i)
{
return 2*i;
}
/* Example function that triples its argument */
int bar1(int i)
{
return 3*i;
}
/* foo takes the function it is passed and applies it to the integer
and returns the result */
int foo(int i, int (*fn)(int))
{
return (fn)(i);
}
int main()
{
int (*bar[2])(int) = {bar0, bar1};
printf("foo(2, bar[0]) returned %d\n", foo(2, bar[0]));
printf("foo(2, bar[1]) returned %d\n", foo(2, bar[1]));
}
This gives:
D:\rhs\c>rat3
foo(2, bar[0]) returned 4
foo(2, bar[1]) returned 6
int foo(int i, int (*fn[2])(int))
{
return (fn[0])(i)*fn[1](i);
}
int main()
{
int (*bar[2])(int) = {bar0, bar1};
printf("foo(2, bar) returned %d\n", foo(2, bar));
}
D:\rhs\c>rat3
foo(2, bar) returned 24
This also works:
int foo(int i, int (*fn[2])(int))
{
return (*(fn+0))(i)*(*(fn+1))(i);
}