Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of ArraySizeof by
main.cpp
- Committer:
- CSTritt
- Date:
- 2017-10-23
- Revision:
- 1:987d0ca5cf9a
- Parent:
- 0:8482415bf245
- Child:
- 2:761d1c20f740
File content as of revision 1:987d0ca5cf9a:
/* Project: ArraySizeof File: main.cpp Ported to mbed/Nucleo by: Dr. C. S. Tritt Last revised: 10/22/17 (v. 1.0) */ #include "mbed.h" int main(void) { // Create a 2-D array. int myNum[3][4] = { { 10, 20, 30, 40 }, // Values for first row { 15, 25, 35, 45 }, // Values for second row { 47, 48, 49, 50 } // Values for third row }; printf("\n\nArray output...\n\n"); // Known sizes. for (int r = 0; r < 3; r++) { for (int c = 0; c < 4; c++) { printf("%d ", myNum[r][c]); } printf("\n"); } // For mbed/Nucleo boards, the final \n is generally required to see output. printf("\nSize of myNum = %u.\n", sizeof(myNum)); // Total size. printf("Size of myNum[0] = %u.\n", sizeof(myNum[0])); // Row size. printf("Size of myNum[0][0] = %u.\n\n", sizeof(myNum[0][0])); // Item size. // Calculated sizes. for (int r = 0; r < sizeof(myNum)/sizeof(myNum[0]); r++) { for (int c = 0; c < sizeof(myNum[0])/sizeof(myNum[0][0]); c++) { printf("%d ", myNum[r][c]); } printf("\n"); } while (true) {} // Loop forever when done. }