Simple training demonstration to show the use of typedef
Fork of StructureExample by
main.cpp@5:eb5c6ae5938b, 2013-11-26 (annotated)
- Committer:
- jf1452
- Date:
- Tue Nov 26 11:18:11 2013 +0000
- Revision:
- 5:eb5c6ae5938b
- Parent:
- 4:c4e451a1890f
- Child:
- 6:5f4be4b8db14
Pointer Example
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jf1452 | 1:d9da28105bef | 1 | /******************************************************************************* |
jf1452 | 5:eb5c6ae5938b | 2 | * This program demonstrates the use of pointers * |
jf1452 | 1:d9da28105bef | 3 | * * |
jf1452 | 1:d9da28105bef | 4 | * Jon Fuge * |
jf1452 | 2:db81cad8cb64 | 5 | * V1.0 25/11/2013 First issue of code * |
jf1452 | 1:d9da28105bef | 6 | *******************************************************************************/ |
dan | 0:7dec7e9ac085 | 7 | |
jf1452 | 2:db81cad8cb64 | 8 | #include "mbed.h" |
jf1452 | 2:db81cad8cb64 | 9 | #include "USBSerial.h" |
jf1452 | 3:0f80147842c2 | 10 | |
jf1452 | 3:0f80147842c2 | 11 | USBSerial serial; // Virtual serial port over USB. Use Teraterm as the interface |
dan | 0:7dec7e9ac085 | 12 | |
dan | 0:7dec7e9ac085 | 13 | int main() { |
jf1452 | 5:eb5c6ae5938b | 14 | char cBox1 = 5; |
jf1452 | 5:eb5c6ae5938b | 15 | char cBox2 = 10; // Declare two variables. |
jf1452 | 5:eb5c6ae5938b | 16 | char *ptr = &cBox1; // Declare a pointer directed to cBox1 |
jf1452 | 5:eb5c6ae5938b | 17 | |
jf1452 | 5:eb5c6ae5938b | 18 | wait (10); // Wait 10 seconds to connect port |
jf1452 | 5:eb5c6ae5938b | 19 | |
jf1452 | 5:eb5c6ae5938b | 20 | serial.printf("cBox1:%i, cBox2:%i, *ptr:%i\n\r", cBox1, cBox2, *ptr); |
jf1452 | 3:0f80147842c2 | 21 | |
jf1452 | 5:eb5c6ae5938b | 22 | cBox2 = cBox1; // cBox2 was 10, but is now 5 |
jf1452 | 5:eb5c6ae5938b | 23 | serial.printf("cBox1:%i, cBox2:%i, *ptr:%i\n\r", cBox1, cBox2, *ptr); |
jf1452 | 5:eb5c6ae5938b | 24 | |
jf1452 | 5:eb5c6ae5938b | 25 | cBox1 = 15; // cBox1 was 5, but is now 15 |
jf1452 | 5:eb5c6ae5938b | 26 | serial.printf("cBox1:%i, cBox2:%i, *ptr:%i\n\r", cBox1, cBox2, *ptr); |
jf1452 | 5:eb5c6ae5938b | 27 | // cBox2 will still report 5, but *ptr now reports 15 |
jf1452 | 3:0f80147842c2 | 28 | |
jf1452 | 5:eb5c6ae5938b | 29 | for(;;) {} // Loop forever |
jf1452 | 3:0f80147842c2 | 30 | } |