2015-11-26 Array Basics Lecture Notes

Source: Internet
Author: User

1, about the size of the array:

When declaring an array in the C language, you need to specify its size (except for flexible arrays), and the size of the array is specified in two ways:

A, specifying the array size explicitly

Eg:int a[5]={1,2};

That is, when declaring an array, the length of the array is filled in square brackets [] in the length of the array, which is the way to explicitly specify the size of the array.

b, implicitly specifying the array size

Eg:int b[] ={1,2};

That is, when declaring an array, the array length is not filled in square brackets, but after the array is initialized, the length of the array is the number of all elements in the curly brace {}.

2, about the initialization of the array:

At this time, someone can't help but ask, when we explicitly specify the array size, int a[5]={1,2}; now that the array length is 5 and the first two elements are 1 and 2, then what is the value of the remaining elements?

Some would say that the value of the remaining elements is random, and as we have tried to prove, this is not true, and the remaining elements have a value of 0.

So what if we were to explicitly specify a numeric length? int a[5];

The result of the teacher running under Linux shows that the values of the elements inside the array are random, and I run under vs found that the values of the array elements are all 0. Anyway, anyway, this shows that the way the array is declared above, the value of the element inside the array is indeterminate.

Then we will initialize the array when we declare it. So how do you initialize the operation?

Let's take advantage of the first feature of the array we just talked about. If we explicitly declare the length of the array and assign the initial values to some of the elements in the array, then the value of the remaining elements is initialized to 0.

So here's how we're going to initialize this: for example, we want to define an array of C, there are 100 elements in the array, but we don't know what the elements are in the array, so we want to initialize the values of the elements inside to 0.

int c[100]={0};

Thus, we initialize the first element to 0, and the remaining elements are initialized to 0. (not to be continued)

2015-11-26 Array Basics Lecture Notes

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.