Home » Archimedes archive » Acorn User » AU 1994-02.adf » !C_Interp_C_Interp » Examples/functions

Examples/functions

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Archimedes archive » Acorn User » AU 1994-02.adf » !C_Interp_C_Interp
Filename: Examples/functions
Read OK:
File size: 01A4 bytes
Load address: 0000
Exec address: 0000
File contents
@* An example of function declaration and parameter passing *@

@*                         *@
@* This is the entry point *@
@*                         *@
main()
{
printf("New record: %d\n",run_print("Bob",99));
}


@*                          *@
@* This is our own function *@
@*                          *@
run_print(char *name, int record)
{
printf("Name:   %s\nRecord: %d\n",name,record);
record++;

return record;
}
00000000  40 2a 20 41 6e 20 65 78  61 6d 70 6c 65 20 6f 66  |@* An example of|
00000010  20 66 75 6e 63 74 69 6f  6e 20 64 65 63 6c 61 72  | function declar|
00000020  61 74 69 6f 6e 20 61 6e  64 20 70 61 72 61 6d 65  |ation and parame|
00000030  74 65 72 20 70 61 73 73  69 6e 67 20 2a 40 0a 0a  |ter passing *@..|
00000040  40 2a 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |@*              |
00000050  20 20 20 20 20 20 20 20  20 20 20 2a 40 0a 40 2a  |           *@.@*|
00000060  20 54 68 69 73 20 69 73  20 74 68 65 20 65 6e 74  | This is the ent|
00000070  72 79 20 70 6f 69 6e 74  20 2a 40 0a 40 2a 20 20  |ry point *@.@*  |
00000080  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000090  20 20 20 20 20 20 20 2a  40 0a 6d 61 69 6e 28 29  |       *@.main()|
000000a0  0a 7b 0a 70 72 69 6e 74  66 28 22 4e 65 77 20 72  |.{.printf("New r|
000000b0  65 63 6f 72 64 3a 20 25  64 5c 6e 22 2c 72 75 6e  |ecord: %d\n",run|
000000c0  5f 70 72 69 6e 74 28 22  42 6f 62 22 2c 39 39 29  |_print("Bob",99)|
000000d0  29 3b 0a 7d 0a 0a 0a 40  2a 20 20 20 20 20 20 20  |);.}...@*       |
000000e0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000000f0  20 20 20 2a 40 0a 40 2a  20 54 68 69 73 20 69 73  |   *@.@* This is|
00000100  20 6f 75 72 20 6f 77 6e  20 66 75 6e 63 74 69 6f  | our own functio|
00000110  6e 20 2a 40 0a 40 2a 20  20 20 20 20 20 20 20 20  |n *@.@*         |
00000120  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000130  20 2a 40 0a 72 75 6e 5f  70 72 69 6e 74 28 63 68  | *@.run_print(ch|
00000140  61 72 20 2a 6e 61 6d 65  2c 20 69 6e 74 20 72 65  |ar *name, int re|
00000150  63 6f 72 64 29 0a 7b 0a  70 72 69 6e 74 66 28 22  |cord).{.printf("|
00000160  4e 61 6d 65 3a 20 20 20  25 73 5c 6e 52 65 63 6f  |Name:   %s\nReco|
00000170  72 64 3a 20 25 64 5c 6e  22 2c 6e 61 6d 65 2c 72  |rd: %d\n",name,r|
00000180  65 63 6f 72 64 29 3b 0a  72 65 63 6f 72 64 2b 2b  |ecord);.record++|
00000190  3b 0a 0a 72 65 74 75 72  6e 20 72 65 63 6f 72 64  |;..return record|
000001a0  3b 0a 7d 0a                                       |;.}.|
000001a4