C language-06 complex data types,-06 Data Types
01-array
# Include <stdio. h> int main () {// note // both are written correctly // int ages [5] = {10, 11, 12, 67, 56 }; // int ages [5] = {10, 11}; // int ages [5] = {[3] = 10, [4] = 11 }; // int ages [] = {10, 11, 14}; // incorrect syntax // int ages []; // incorrect syntax/* Only int ages [5] can be initialized while defining arrays; ages = {10, 11, 12, 14 }; // because the array name stores A pointer * /// correct writing // int ages ['a'-50] = {10, 11, 12, 14, 16 }; // 65-50 -- "15 // int size = sizeof (ages); 15*4 -----" 60 // printf ("% d \ n", size ); // write the statement correctly/* int count = 5; int ages [count]; ages [0] = 10; ages [1] = 11; ages [2] = 18; * /// printf (); // incorrect syntax // if you want to define an array of colleagues for initialization, the number of array elements must be a constant, or do not write // int ages [count] = {10, 11, 12}; int ages [] = {10, 11, 12, 78 }; // calculate the number of array elements int count = sizeof (ages)/sizeof (int); for (int I = 0; I <count; I ++) {printf ("ages [% d] = % d \ n", I, ages [I]);} return 0;} // The basic array uses void arrayUse () {// Definition Format of the array: type array name [number of elements]; int ages [5] = {19, 29, 28, 27, 26 }; // 19 19 28 27 26] ages [1] = 29;/* ages [0] = 19; ages [1] = 19; ages [2] = 28; ages [3] = 27; ages [4] = 26; * // * traversal: view each element of the array in order */for (int I = 0; I <5; I ++) {printf ("ages [% d] = % d \ n", I, ages [I]);}