Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Can one-dimensional integer array and one-dimensional character array be used interchangeably? Why
Can one-dimensional integer array and one-dimensional character array be used interchangeably? Why

No.

Character array refers to an array used to store character data. Character arrays are used to store characters or strings. An element in a character array stores a character, which occupies one byte in memory. That is, the elements of the character array only occupy 1 byte.

The integer type specifier is int, which may occupy 2 or 4 bytes in memory depending on the computer's internal word length and compiler version (usually on 16-bit machines and 32-bit machines respectively) ), its value is a basic integer constant.

Thus, a one-dimensional integer array and a one-dimensional character array cannot be used interchangeably because the types do not match.

Extended information:

Memory principle of one-bit array:

In the declaration format of the array, "data type" is the data type of the declared array element. "Array name" is a name used to unify these same data types, and its naming rules are the same as those of variables. After the array is declared, the next step is to allocate the memory required for the array. At this time, the operator new must be used.

The "number" tells the compiler how many elements the declared array should store, so the new operator notifies the compiler to allocate a space in the memory for the element based on the number in the brackets. Array usage. The method of allocating memory space for array elements using the new operator is called dynamic allocation.

Baidu Encyclopedia-Character Array

Baidu Encyclopedia-Array

Baidu Encyclopedia-Integer