In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge of "what is the difference between an and & an in C language array". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
First, look at a piece of code:
# include
Int main (void)
{
Int a [5] = {0pm 1pm 2pm 3je 4}
Printf ("a =% d, & a =% d\ n", a, & a)
Return 0
The running result of the code is:
As you can see, for an array:
Int a [5] = {0pm 1pm 2pm 3je 4}
The values of an and & an are the same. Why?
An is the array name, the constant of a data area, and the address of the array storage area can be obtained by taking the address (& a). Similarly, an itself represents the first address of the array storage area. So, the values of an and & an are the same. However, although an and & a point to the same address, they have different meanings. Let's modify the above code to see if "axi1" and "& axi1" are still equal. The result of the modified code is:
It can be seen that the value of axi1 is 4 greater than the value of a, that is, sizeof (a [0]); & axi1 is 20 greater than the value of & a, that is, sizeof (a). From this, it can be concluded that the address pointed to by aqum1 is sizeof (a [0]) bytes backward relative to the address pointed to by a, and the address pointed to by & an is offset by sizeof (a) bytes relative to the address pointed to by & a. The description figure is as follows:
After looking at this picture, you must have a clear understanding of an and & a. Let's analyze a piece of code:
# include
Int main (void)
{
Int a [5] = {0pm 1pm 2pm 3je 4}
Int* ptr = (int*) (& axi1)
Printf ("* (axi1) =% d, * (ptr-1) =% d\ n", * (axi1), * (ptr-1))
Return 0
}
What is the result of the operation?
The running result is:
* (axi1) = 1, * (ptr-1) = 4
* (ptr-1 1) = 1, because ptr-1 1 represents the address of the second element of the array, that is, & a [1], * (aqui1) is the value on this address, that is, 1 ptr-1 * (address) = 4, because the address points to the memory after the whole memory area of the array, that is, the address after the last element of the array, the address points to the last element of the array, and * (ptr-1) refers to the value on that address, that is, 4.
This is the end of the content of "what's the difference between an and & an in the C language array". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.