In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to create and initialize one-dimensional and two-dimensional arrays in C language. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
(1) creation and initialization of one-dimensional array 1.1 creation of array
An array is a collection of elements of the same type. How the array is created:
Instance created by array
Note: array creation, a constant must be given in [], variables cannot be used.
1.2 initialization of the array
The initialization of an array means that some reasonable initial values (initialization) are given to the contents of the array while creating the array.
Except for a few initialized elements, the default is 0
Create as much space as there are elements.
When an array is created, it has to be initialized if you do not want to specify the definite size of the array. The number of elements in the array is determined according to the initialized content. But for the following code to distinguish, how to allocate memory.
1.3 use of one-dimensional arrays
For the use of arrays, we introduced an operator: [], the subscript reference operator. It is actually the operator of array access.
Remember: the subscript starts with 0! ?
? The array is accessed using the subscript, which starts at 0.
? The size of the array can be calculated.
1.4 Storage of one-dimensional array in memory
? The output is as follows:
Looking closely at the output, we know that as the array subscript grows, the address of the element increases regularly. It can be concluded that the array is stored continuously in memory.
(II) creation and initialization of 2D array 2.1 creation and initialization of 2D array
2.2 use of two-dimensional arrays
2.3 Storage of two-dimensional arrays in memory
Like an one-dimensional array, here we try to print each element of a two-dimensional array.
Through the analysis of the results, we can see that the two-dimensional array is also continuously stored in memory.
This is the end of the article on "how to create and initialize one-dimensional and two-dimensional arrays in C language". I hope the above content can be helpful to you, so that you can learn more knowledge. If you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.