Basic array knowledge, basic learning of vba Array
/* ===================================================== ============================================================ Name: testArray. c Author: lf Version: Copyright: Your copyright notice Description: basic use of arrays ================================================== ========================================================== */# include <stdio. h> # include <stdlib. h> int main (void) {getArraySizeAndSize (); copyArray (); testCharArray (); return EXIT_SUCCESS;}/*** get the size of the memory occupied by the array and the size of the array Length * use & array [I] and array + I to retrieve the address of each element * array + I why can I retrieve the address of each element? * Because array represents the address of the first element, + 1 * indicates the next element, similarly, + I indicates the address of the I-th element starting from the first element ** Summary: * array [I] And * (array + I) equivalent to * & array [I] and array + I */void getArraySizeAndSize (void) {int array [5] = {0, 1, 2, 3, 4 }; // memory size occupied by the array int arraySize = sizeof (array); // The length of the Array int arrayLength = sizeof (array)/sizeof (int); printf ("array allocated memory: % dByte, Array length: % d \ n ", arraySize, arrayLength ); // traverse the Array // obtain the first address of the array printf ("Array start address = % d \ n", array); // traverse the Array element int I; for (I = 0; I <arrayLength; I ++) {printf ("array [% d] = % d, address is % d, % d \ n", I, array [I], & array [I], array + I) ;}/ *** arrays cannot be directly assigned values. * Because the array name is the address of the first element of the array */void copyArray () {int a [2] = {1, 2}; int B [2]; // B =; // error. // use a for loop to continuously initialize elements in array B}/*** Note: * 1 printf ("% s \ n", charArray) can be used ); character array * 2. Note that the last character in the character array should be \ 0 as the terminator * 3. You can use a string to directly assign values to a character array. * In this way, \ 0 */void testCharArray () {char charArray [5] = {'h', 'F', 'A ', 'B', '\ 0'}; printf ("% s \ n", charArray ); // if "" is used, \ 0 char charArray2 [10] = {"hello"} will be automatically added at the end of it "}; // It can be abbreviated as // char charArray2 [10] = "hello"; printf ("% s \ n", charArray2 );}