Initialization of arrays and two-dimensional arrays, pointers and arrays

Source: Internet
Author: User

1, the initialization of the array, relatively simple, the instance is as follows:

#include <stdio.h># define M 12int main (void) {int Days[m]={31,28,31,30,31,30,31,30,30,31,30,31};int i;for (i=0;i <m;i++) printf ("Months%d has%2d days.\n", I+1,days[i]); return 0;}

The results of the operation are as follows:

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/9D/C2/wKiom1mFclGASF3AAAAbKFdFV3Y993.png "title=" Untitled. png "alt=" Wkiom1mfclgasf3aaaabkfdfv3y993.png "/>

2. Uninitialized array:

Instance program;

#include <stdio.h># define M 12int main (void) {int n[m];//non-initialized array int days[m]={ 31,28,31,30,31,30,31,30,30,31,30,31};int i;for (i=0;i<m;i++)//printf ("Months%d has%2d days.\n", I+1,days[i]); printf ("%d%d\n", I,n[i]); return 0;}

Operation Result:

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/9D/C3/wKiom1mFdDri7apAAAAYrBIX32k377.png "title=" Untitled. png "alt=" Wkiom1mfddri7apaaaayrbix32k377.png "/>

It can be concluded that before initialization, the value of the array element is indeterminate, and the compiler uses a value that is already in the storage unit, and the output above is not necessarily.

3, in the initialization of the array, the compiler is very witty, even if you give the number of elements less than or for a given array size, the compiler will automatically recognize, not enough, it will use 0 instead. However, when there are too many pairs of numbers in the initialization list, the compiler warns of errors. Too many initializers too much initialization. The following is the deletion of several elements, the result:

#include <stdio.h># define M 12int main (void) {int n[m];//non-initialized array int days[m]={31,28,31,30,31,30,31,30};int i;for (i=0;i<m;i++) printf ("Months%d has%2d days.\n", I+1,days[i]);//printf ("%d%d\n", I,n[i]); return 0;}

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/9D/C3/wKiom1mFdXOjwzWwAAAu-P9F5DE654.png "title=" Untitled. png "alt=" Wkiom1mfdxojwzwwaaau-p9f5de654.png "/>

4, two-dimensional array, for a chestnut: float rain[5] [12] First,Rain[5] represents an array of five elements, for each element of the case, you need to see the rest of the declaration. The remaining is the float "12", which represents an array of 12 floating-point numbers. In summary, the two-dimensional array represents: Rain has 5 elements, and each element is an array of 12 numeric values.

The specific understanding of the drawing is as follows: It is quite clear.

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/9D/C4/wKioL1mFmnizRzCMAAQqD84Jjmo021.jpg "title=" Drawing 2.jpg "alt=" Wkiol1mfmnizrzcmaaqqd84jjmo021.jpg "/>



5. Pointers and Arrays

Pointers provide a way for you to use an address

Initialization of arrays and two-dimensional arrays, pointers and arrays

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.