Demonstrate basic pointer use.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
CSTritt
Date:
Thu Nov 04 13:13:30 2021 +0000
Parent:
0:f4431aea05f2
Commit message:
Added explicit serial port creation, but not fully updated.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- 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