laitimes

This article will give you an understanding of one-dimensional arrays, two-dimensional arrays, character array arrays in C: two-dimensional arrays: character arrays:

author:ArveyCheung

When writing C code, arrays are used very frequently in many development scenarios. Since it is important, it is first necessary to know the definition and usage of arrays.

This article will give you an understanding of one-dimensional arrays, two-dimensional arrays, character array arrays in C: two-dimensional arrays: character arrays:

array

<h1 class="pgc-h-arrow-right" data-track="3" > array:</h1>

When we define an array, we should pay attention to the brackets in [] in the array, the value in [] cannot be a variable, [] can only be a constant.

Using arrays:

When using arrays, the values in parentheses of [] in the array can be constants or variables. A numeric array cannot be manipulated as a whole, and each element of the array is a variable and can be assigned a variable; if the array only initializes some elements and other elements are initialized to 0; # Note: If there is no value in the brackets of [] when defined, the number of elements in this array is determined by the number of elements in the {} braces; for example, look at the following code demonstration:

The resulting graph is:

This article will give you an understanding of one-dimensional arrays, two-dimensional arrays, character array arrays in C: two-dimensional arrays: character arrays:

When I get the array, how do I know the address of the data in memory?

It can be interpreted as the address of the data in memory, which is its starting address in memory. For example, define an array int arr[5];

How do I know what int arr[5] means?

Where arr[0] represents the 0th element, and the addition of the &amp; reference symbol &amp;arr[0] preceding it represents the address of the 0th element (also known as the first element address); arr is the array name, which represents the array and also represents the address of the 0th element.

Expressed as a relation: arr == &amp;arr[0]; so the array name is a constant (which cannot be assigned) and an address.

Caution indicator:

&amp;arr[0]+1 or &amp;arr[0]+2 represents the address of the 0th element plus 1 across one element, or 2 across two elements;

arr+1 or arr+2 represents the address of the 0th element plus 1 across one element, or 2 across two elements;

&amp;arr+1 represents the address of the entire array plus 1 that spans the entire array;

This article will give you an understanding of one-dimensional arrays, two-dimensional arrays, character array arrays in C: two-dimensional arrays: character arrays:

Two-dimensional arrays

<h1 class="pgc-h-arrow-right" data-track="19" > two-dimensional array:</h1>

When defining two-dimensional arrays, there is a caveat: you cannot omit the subscript of a column, but you can omit the subscript of a row.

For example, this two-dimensional array: int arr[4][5];

arr[0][0]: represents the 0th element of line 0;

&amp;arr[0][0]: Represents the address of the 0th element in line 0;

arr[0]: represents the array name of the one-dimensional array in row 0;

&amp;arr[0]: Represents the address of line 0;

arr: represents the array name of a two-dimensional array (representing a two-dimensional array), but also represents the first line address;

&amp;arr: represents the address of a two-dimensional array;

Relationships mean:

&amp;arr[0][0]+1: Represents the address of the 0th element in line 0 plus 1 that spans an element;

arr[0]+1: represents the element address of line 0 plus 1 across an element;

&amp;arr[0]+1: Represents the address of line 0 plus 1, spanning one line;

arr+1: represents the first line of address plus 1, spanning one line;

&amp;arr+1: Represents a two-dimensional array of addresses plus 1, spanning the entire array.

This article will give you an understanding of one-dimensional arrays, two-dimensional arrays, character array arrays in C: two-dimensional arrays: character arrays:

An array of characters

<h1 class="pgc-h-arrow-right" data-track="36" > character array:</h1>

First of all, let's understand what are numeric arrays and character arrays?

1, the array of values: int arr[5] each element int type;

2, character array: char arr[5] Each element is of type char;

When it comes to character arrays, strings are generally thought of, and the difference between them is:

Strings: Arrays with \0 characters in a character array are called strings, and in addition, character arrays with \0 characters are also more convenient to operate.

Character array: If the character array contains the character \0, it is also a string;

Next, the input and output using sfgets and fputs are demonstrated in code:

Read on