![](/media/cache/profiles/Headshot_Fall2023_Square.jpg.50x50_q85.jpg)
Demonstrate basic pointer use.
Diff: main.cpp
- Revision:
- 1:66b36106613a
- Parent:
- 0:f4431aea05f2
diff -r f4431aea05f2 -r 66b36106613a main.cpp --- a/main.cpp Fri Nov 03 02:19:44 2017 +0000 +++ b/main.cpp Thu Nov 04 13:13:30 2021 +0000 @@ -5,10 +5,11 @@ Demonstrates some uses of pointers. Written by: Dr. C. S. Tritt - Created: 9/24/17 (v. 1.0) + Created: 11/4/21 (v. 1.1) */ #include "mbed.h" +Serial pc(USBTX, USBRX, 9600); // Explicitly create serial connection. int main() { printf("\nPointer Play -- \"a is a.\"\n"); @@ -20,8 +21,8 @@ int* pNum2 = NULL; // Create a NULL (unassigned) pointer. pNum2 = &myNum2; // Put the address in the pointer. *pNum2 = 15; // Dereference the pointer to store a value. - printf("myNum2 is %d and *pNum2 is %d.\n", myNum2, *pNum2); + pc.printf("myNum2 is %d and *pNum2 is %d.\n", myNum2, *pNum2); // Examine the addresses (pointer values). - printf("pNum1 is %p and pNum2 is %p.\n", pNum1, pNum2); + pc.printf("pNum1 is %p and pNum2 is %p.\n", pNum1, pNum2); while(true); // Wait here forever. } \ No newline at end of file