Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * This code has issues in the sizes and usage of its arrays
- */
- #include <stdio.h>
- #define MAX_ROW 10
- # define MAX_COL 10
- //Function prototypes
- void print1DArray(int[]);
- void print2DFLAArray(int[][MAX_COL]);
- void print2DVLAArray(int[MAX_ROW][MAX_COL]);
- int main() {
- //Local declarations
- int ary1[0];
- int ary2[] = {
- 1,
- 2,
- 3,
- 4,
- 5,
- 6,
- 7,
- 8,
- 9
- };
- int x = 10;
- int y = 10;
- int ary3[x][y]; //VLA
- int ary4[][]; //FLA
- //Local Statements
- ary1[1] = 20;
- ary2[11] = 20;
- return 0;
- } //end main
- void print1DArray(int aryIn[]) {
- printf("Array: ");
- for (int i = 0; i < MAX_COL; i++) {
- printf("%d ", aryIn[i]);
- }
- printf("\n");
- return;
- } //end function
- //Note how the FLA 2d Array needs to know the size of columns
- void print2DFLAArray(int aryIn[][MAX_COL]) {
- printf("2dArray: \n");
- for (int i = 0; i < MAX_ROW; i++) {
- for (int j = 0; j < MAX_COL; j++) {
- printf(" %d ", aryIn[i][j]);
- } //end inner for
- printf("\n");
- } //end outer for
- printf("\n");
- return;
- }
- //Note how the VLA 2d Array needs to know both sizes of rows and columns
- void print2DVLAArray(int aryIn[MAX_ROW][MAX_COL]) {
- printf("2dArray: \n");
- for (int i = 0; i < MAX_ROW; i++) {
- for (int j = 0; j < MAX_COL; j++) {
- printf(" %d ", aryIn[i][j]);
- } //end inner for
- printf("\n");
- } //end outer for
- printf("\n");
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement