Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the creation and initialization of two-dimensional array in C language

Shulou Source: shulou.com Published: 2022-06-01 03:06:28 10月05日 Update

This article is about how C language implements the creation and initialization of two-dimensional arrays. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Creation and initialization of two-dimensional arrays 1 creation of two-dimensional arrays int arr [3] [4]; char arr [3] [5]; double arr [2] [4]

Int arr [3] [4]

2 initialization of two-dimensional array int arr [3] [4] = {1pr 2je 3je 4}; / / if it is not fully initialized, add 0int arr [3] [4] = {{1pr 2}, {4pr 5}} / / 1 200 / / 4 500 / / 000 0int arr [] [4] = {{2jue 3}, {4pm 5}} / / if the two-dimensional array is initialized, the row can be omitted, and the column cannot be omitted. 3 the use of the two-dimensional array / / print the two-dimensional array int arr [3] [4] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; int I = 0; for (I = 0; I < 3; iTunes +) {int j = 0 For (j = 0; j < 4; jacks +) {printf ("% d", arr [I] [j]) }} 4 two-dimensional array storage / / print array address of each element int arr [3] [4] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; int I = 0; for (I = 0; I < 3; iTunes +) {int j = 0 For (j = 0; j < 4; jacks +) {printf ("& arr [% d] [% d] =% p\ n", iMagnej, & ARR [I] [j]);}}

Two-dimensional array storage seems to be discontinuous, but in fact it is continuous.

Thank you for reading! This is the end of the article on "how to create and initialize two-dimensional arrays in C language". I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, you can share it for more people to see!

Tags: Array two-dimensional language content more articles jacks articles good practical not enough elements memory addresses articles see knowledge reference storage help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Apple Shulou Information OPPO Reno Linux