In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "the detailed introduction of array names an and & an in c language". The explanation in this article is simple and clear and easy to learn and understand. let's study and learn the detailed introduction of array names an and & an in c language.
Let's first talk about the difference between an and & a (there are three points, three directions):
Is the essence of an and & a, what type are they?
From the perspective of a 2-dimensional array.
From the point of view of pointer operation.
Disclaimer: although the array name is not a pointer, it is used very much like a pointer. Let's call it a pointer for the time being.
* * questions:
What are int a [10]; a, & an and & a [0] respectively? First of all, it is stated that the values of a, & an and & a [0] are equal.
An is called the array name and is the address of the first element of the array, that is, the value of & a [0]. It's like a pointer type, it's an int pointer type, int *, first understand it as a pointer.
& a this is a real pointer, an array pointer. Is the address of the array.
Remember: & an is not a pointer to a pointer because the values of & an and an are equal, but the values of * & an and * an are not equal. The value of * & an is the same as that of a, which means that * & an only takes the value of the array pointer and gets the value of the array, that is, the address of the first element of the array, not the address of & a. This should be the specification of array pointer operation in c language.
When the array pointer & an is taken, it becomes a, it is a, not * a, and it becomes the array name of the array, or the address of the first element of the array.
I did the following experiments:
# include int main {int a [5] = {1pm% x\ n ", a); printf (" & A% x\ n ", & a); printf (" * (int*) & A% x\ n ", (* ((int*) (& a); printf (" * & a% x\ n ", (* (* (& a); printf (" & a [0] =% x\ n ", & a [0])) Printf ("* & a [0] =% x\ n", * (& a [0])); return 0;} printf ("* (int*) & a% x\ n", (* (int*) (& a)
This sentence does not take the value of & an as usual, but forces the type conversion, which shows that this is not a pointer to a pointer.
The second question:
The way of traversing through a pointer in a two-dimensional array is not a pointer to a pointer (level 2 pointer). The sentence printf ("% d\ n", * (* (axii) + j); * (axii) is to get the first element address of the array by taking the value of the array pointer. The common misunderstanding is that the operation of the array pointer is different from the ordinary pointer value operation. The operation of array pointer value is similar to the process of casting type.
Note: the array name an of a two-dimensional array is the array pointer of * one-dimensional arrays, and * an is the array name of * one-dimensional arrays. You can also cast directly with tpye *.
# include int main (int argc, char* argv, char* env) {int a [3] [3] = {{0,1,2}, {3,4,5}, {6,7,8}}; int iTuno; int j = 0; for (iTun0; I)
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.