Get the App
SLTechnology News&Howtos  ›  Development  › 

There are several types of arrays in c language

Shulou Source: shulou.com Published: 2022-06-03 17:41:40 09月12日 Update

This article mainly introduces several types of arrays in c language, which can be used for reference. Interested friends can refer to them. I hope you will gain a lot after reading this article.

1. An one-dimensional array. The type before the array name when declared is the type of the array element.

Example: inta [4]; this indicates that the length of an integer array is 4, and each element is an integer array.

The assignment method for grouping is as follows:

Array type array name [length of custom array] array name [subscript] = value int array name [length of array] = {the first element of the array, the second element of the array,..., the nth element of the array}

We usually assign values to arrays through for loops.

Note: if an element in the array is not assigned, the default value is 0.

2, two-dimensional array, can be used as a kind of table, it has rows and columns.

Example: array type array name [length of one-dimensional array in array] [length of two-dimensional array in array]

Assignment of two-dimensional array:

Array type array name [length of one-dimensional array] [length of two-dimensional array]; array name [subscript of an element of an one-dimensional array] [subscript of an element of a two-dimensional array] = value

3. Character array, there is no concept of string in c language, only a single character, so a string is called a character array.

The definition of character array is as follows:

Char string name [string length] = "here is your string"

In addition, the string in c language should end with\ 0, otherwise the character array does not have an end.

Thank you for reading this article carefully. I hope the article "there are several types of arrays in c language" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Array character element length type string two-dimensional language article one-dimensional subscript value interest single only at the same time name method more friends Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Microsoft Shulou Tech Info Apple Huawei