编程知识 cdmana.com

Geek University Java advanced training camp

C In language , Array [2] Belongs to the construction data type . An array can be decomposed into multiple array elements , These array elements can be basic data types or construction types . So it's different according to the type of array elements , Array can be divided into numerical array 、 A character array 、 Pointer array 、 Structure array and other categories .
About variable length arrays (VLA) The problem of : The original C89 Variable length arrays are not allowed in the standard , But in C99 In the standard , Joined the right VLA Support for [3], But not many compilers are supported , And because of the security problem of stack overflow , Not many people dare to use this variable length array , So in C11 It is defined as an optional function in the standard [4].
If you have experience programming in other languages , Then I will be familiar with the concept of array . With arrays , You can refer to a series of variables with the same name , And use numbers ( Indexes ) To identify them . on many occasions , Using arrays can shorten and simplify programs , Because you can design a loop with index values , Handle a variety of situations efficiently . Arrays have upper and lower bounds , The elements of an array are continuous within the upper and lower bounds . because Visual Basic Allocate space for each index value , So don't unrealistically declare an array that's too large .
Here the array is an array of variables declared in the program . They are different from control arrays , Control array is designed by setting controls Index Attribute specified . Arrays of variables are always continuous ; Unlike control arrays , Array elements cannot be loaded or unloaded from the middle of an array .
All elements in an array have the same data type ( stay C、C++、Java、pascal It's the same in China . But it's not all about arrays , For example Visual Foxpro There is no such requirement for arrays in ). Of course , When the data type is Variant when , Each element can contain different kinds of data ( object 、 character string 、 Values, etc ). You can declare an array of any basic data type , Including user-defined types and object variables .
If you want the user to input an array , It's usually a cycle , But you also need to fix the size of the array before you input it .
compact It doesn't have much to do with variable length arrays , There should be no variable length arrays . Because the general pass array to the function is to pass the address of the array and the number of elements , That's just a hint , It's not a request .
Prototypes can be written like this ( Suppose the elements of an array are type):
int compact(type *Array,int Count)
Array type description stay C In the language, the array must be typed first .
The general form of array description is : Type specifier Array name [ Constant expression ],……; among , A type specifier is any basic or constructive data type . The array name is a user-defined array identifier . The constant expression in square brackets represents the number of data elements , Also known as the length of an array .
An array is a set of variable array definitions that define the same data type at one time .
give an example
Description integer array a, Yes 10 Elements . If you want to express the 10 Elements , Then use a[9]. The first is a[0].
int a[10];
Explain real arrays b, Yes 10 Elements , Real array c, Yes 20 Elements .

版权声明
本文为[Vx_ itstudy01]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201224214844035o.html

Scroll to Top