Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Definition of array in c language
Definition of array in c language

C language supports one-dimensional arrays and multi-dimensional arrays. If all the elements of an array are not arrays, then the array is called a one-dimensional array.

To use an array in C language, it must be defined first. A one-dimensional array is defined as: type specifier; array name; [constant expression].

Among them, the type specifier is any basic data type or constructed data type. The array name is a user-defined array identifier, and the constant expression in square brackets represents the number of data elements, also known as the length of the array. For example:

int a[10]; ?/* Indicates the integer array a, which has 10 elements*/

float b[10], c[20]; ?/ * Describes the real array b, which has 10 elements, and the real array c, which has 20 elements*/

char ch[20]; ?/* Describes the character array ch, which has 20 elements*/

The following points should be noted when describing array types:

1. The type of an array actually refers to the value type of the array elements. For the same array, the data type of all its elements is the same.

2. The writing rules for array names should comply with the writing rules for identifiers.

3. The array name cannot be the same as other variable names. For example:

int a;

float a[10];

is wrong.

4. The constant expression in square brackets indicates the number of array elements. For example, a[5] indicates that array a has 5 elements. But its subscript starts from 0. Therefore, the five elements are a[0], a[1], a[2], a[3], a[4].

5. Variables cannot be used in square brackets to represent the number of elements, but they can be symbolic constants or constant expressions. For example:

#define FD 5

// ...

int a[3+2],b[7+FD];

is legal. But the following explanation is wrong.

int n=5;

int a[n];

6. Allow multiple arrays and multiple variables to be specified in the same type specification . For example:

int a,b,c,d,k1[10],k2[20];

Extended information:

C language is a A general-purpose computer programming language that is widely used in low-level development. The design goal of the C language is to provide a programming language that can be easily compiled, handle low-level memory, generate a small amount of machine code, and can run without any runtime environment support.

Although C language provides many low-level processing functions, it still maintains good cross-platform characteristics. C language programs written in a standard specification can be compiled on many computer platforms, even including some Embedded processors (single-chip microcomputer or MCU) and supercomputers and other operating platforms.

In the 1980s, in order to avoid differences in the C language syntax used by various developers, the American National Standards Institute formulated a complete set of American national standard syntax for the C language, called ANSI C. , as the original standard of C language. [1] Currently on December 8, 2011, the C11 standard released by the International Organization for Standardization (ISO) and the International Electrotechnical Commission (IEC) is the third official standard for the C language and the latest standard for the C language. This standard is better Supports Chinese character function names and Chinese character identifiers, realizing Chinese character programming to a certain extent.

C language is a process-oriented computer programming language, which is different from object-oriented programming languages ??such as C++ and Java.

The main compilers include Clang, GCC, WIN-TC, SUBLIME, MSVC, Turbo C, etc.