C language-06 complex data types,-06 Data Types

Source: Internet
Author: User

C language-06 complex data types,-06 Data Types
01-array

# Include <stdio. h> int main () {// note // both are written correctly // int ages [5] = {10, 11, 12, 67, 56 }; // int ages [5] = {10, 11}; // int ages [5] = {[3] = 10, [4] = 11 }; // int ages [] = {10, 11, 14}; // incorrect syntax // int ages []; // incorrect syntax/* Only int ages [5] can be initialized while defining arrays; ages = {10, 11, 12, 14 }; // because the array name stores A pointer * /// correct writing // int ages ['a'-50] = {10, 11, 12, 14, 16 }; // 65-50 -- "15 // int size = sizeof (ages); 15*4 -----" 60 // printf ("% d \ n", size ); // write the statement correctly/* int count = 5; int ages [count]; ages [0] = 10; ages [1] = 11; ages [2] = 18; * /// printf (); // incorrect syntax // if you want to define an array of colleagues for initialization, the number of array elements must be a constant, or do not write // int ages [count] = {10, 11, 12}; int ages [] = {10, 11, 12, 78 }; // calculate the number of array elements int count = sizeof (ages)/sizeof (int); for (int I = 0; I <count; I ++) {printf ("ages [% d] = % d \ n", I, ages [I]);} return 0;} // The basic array uses void arrayUse () {// Definition Format of the array: type array name [number of elements]; int ages [5] = {19, 29, 28, 27, 26 }; // 19 19 28 27 26] ages [1] = 29;/* ages [0] = 19; ages [1] = 19; ages [2] = 28; ages [3] = 27; ages [4] = 26; * // * traversal: view each element of the array in order */for (int I = 0; I <5; I ++) {printf ("ages [% d] = % d \ n", I, ages [I]);}

 

Related Article

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.