Basic array knowledge, basic learning of vba Array

Source: Internet
Author: User

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 );}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.