Home » Archimedes archive » Acorn User » AU 1994-02.adf » !C_Interp_C_Interp » Examples/variables
Examples/variables
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/variables |
Read OK: | ✔ |
File size: | 01E5 bytes |
Load address: | 0000 |
Exec address: | 0000 |
File contents
@* An example of variable scope *@ @* The following is global *@ int value; main() { char a_byte; char string[8]; int i; value=10; printf("Value 1: %d Value 2: %d\n",value,get_value()); strcpy(string,"ABCDEFG"); a_byte=*(string+2); printf("The byte is: %c\n",a_byte); a_byte=string[4]; printf("The byte is: %c\n",a_byte); printf("Enter a number: "); scanf("%d",&i); printf("\nYou entered %d!\n",i); } get_value() { @* The following is local *@ int value=20; return value; }
00000000 40 2a 20 41 6e 20 65 78 61 6d 70 6c 65 20 6f 66 |@* An example of| 00000010 20 76 61 72 69 61 62 6c 65 20 73 63 6f 70 65 20 | variable scope | 00000020 2a 40 0a 0a 40 2a 20 54 68 65 20 66 6f 6c 6c 6f |*@..@* The follo| 00000030 77 69 6e 67 20 69 73 20 67 6c 6f 62 61 6c 20 2a |wing is global *| 00000040 40 0a 69 6e 74 20 76 61 6c 75 65 3b 0a 0a 6d 61 |@.int value;..ma| 00000050 69 6e 28 29 0a 7b 0a 63 68 61 72 20 61 5f 62 79 |in().{.char a_by| 00000060 74 65 3b 0a 63 68 61 72 20 73 74 72 69 6e 67 5b |te;.char string[| 00000070 38 5d 3b 0a 69 6e 74 20 20 69 3b 0a 0a 76 61 6c |8];.int i;..val| 00000080 75 65 3d 31 30 3b 0a 70 72 69 6e 74 66 28 22 56 |ue=10;.printf("V| 00000090 61 6c 75 65 20 31 3a 20 25 64 20 20 56 61 6c 75 |alue 1: %d Valu| 000000a0 65 20 32 3a 20 25 64 5c 6e 22 2c 76 61 6c 75 65 |e 2: %d\n",value| 000000b0 2c 67 65 74 5f 76 61 6c 75 65 28 29 29 3b 0a 0a |,get_value());..| 000000c0 73 74 72 63 70 79 28 73 74 72 69 6e 67 2c 22 41 |strcpy(string,"A| 000000d0 42 43 44 45 46 47 22 29 3b 0a 0a 61 5f 62 79 74 |BCDEFG");..a_byt| 000000e0 65 3d 2a 28 73 74 72 69 6e 67 2b 32 29 3b 0a 70 |e=*(string+2);.p| 000000f0 72 69 6e 74 66 28 22 54 68 65 20 62 79 74 65 20 |rintf("The byte | 00000100 69 73 3a 20 25 63 5c 6e 22 2c 61 5f 62 79 74 65 |is: %c\n",a_byte| 00000110 29 3b 0a 0a 61 5f 62 79 74 65 3d 73 74 72 69 6e |);..a_byte=strin| 00000120 67 5b 34 5d 3b 0a 70 72 69 6e 74 66 28 22 54 68 |g[4];.printf("Th| 00000130 65 20 62 79 74 65 20 69 73 3a 20 25 63 5c 6e 22 |e byte is: %c\n"| 00000140 2c 61 5f 62 79 74 65 29 3b 0a 0a 70 72 69 6e 74 |,a_byte);..print| 00000150 66 28 22 45 6e 74 65 72 20 61 20 6e 75 6d 62 65 |f("Enter a numbe| 00000160 72 3a 20 22 29 3b 0a 73 63 61 6e 66 28 22 25 64 |r: ");.scanf("%d| 00000170 22 2c 26 69 29 3b 0a 70 72 69 6e 74 66 28 22 5c |",&i);.printf("\| 00000180 6e 59 6f 75 20 65 6e 74 65 72 65 64 20 25 64 21 |nYou entered %d!| 00000190 5c 6e 22 2c 69 29 3b 0a 7d 0a 0a 67 65 74 5f 76 |\n",i);.}..get_v| 000001a0 61 6c 75 65 28 29 0a 7b 0a 40 2a 20 54 68 65 20 |alue().{.@* The | 000001b0 66 6f 6c 6c 6f 77 69 6e 67 20 69 73 20 6c 6f 63 |following is loc| 000001c0 61 6c 20 2a 40 0a 69 6e 74 20 76 61 6c 75 65 3d |al *@.int value=| 000001d0 32 30 3b 0a 0a 72 65 74 75 72 6e 20 76 61 6c 75 |20;..return valu| 000001e0 65 3b 0a 7d 0a |e;.}.| 000001e5