C Base Array

Source: Internet
Author: User

An array is literally a combination of a set of numbers

The use of arrays I think it's more convenient to create the same type of data

For example, to create 100 numbers without an array, you must int a = 1;int b = 2 ...

But the use of arrays does not require so much int a[100]= {1,2,3,4,5 ...};

It's a lot easier.

Start by understanding the array from the bottom of the memory storage: The array is in memory in a contiguous address form, each memory occupies a size that you define the type of the array, for example, int arr[10] then the distance between arr[1] and Arr[0 is 4 bytes

Char arr[10] The distance between arr[0] and arr[1] is 1 bytes

If it is a two-dimensional array, his address is so stored arr[0][0]arr[0][1]arr[1][0]arr[1][1]; and the distance between each element is the size of the type you define

There are some situations that require special attention when defining a character array, such as defining a character array char c[10]={' h ', ' e ', ' l ', ' l ', ' o '}, or char c[10]= "Hello", if char arr[] = {' h ', ' e ', ' l ', ' l ', ' O '};sizeof (arr), the result is 6, because the character type array ends with/0, and he says that takes up an element, and the output is using%c

In the definition string array is, the same ending is/0 and occupies an element. Output with%s. Char ch[] = {"Hello", "World"}; This is three elements, the first arr[0] is Hello, the second element arr[1] is world, the third is the end of/0;

int arr[4] = {0}; Arr is actually arr[0];

C Base Array

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.