In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
# include
Int main ()
{
Int * ptr; / / declare an int pointer
Int val = 1; / / declare an int value
Ptr = & val; / / assigns a reference to the int value to the pointer
Int deref = * ptr; / / A pair of pointers take values and print what is stored in the pointer address
Printf ("deref address =% ld, value =% d\ n", ptr, deref)
}
In line 2, we declare an int pointer through the * operator. Then we declare an int variable and assign it to 1. Then we initialize our int pointer with the address of the int variable. Next, take the value of the int pointer and initialize the int pointer with the memory address of the variable. Finally, we print out the value of the variable with a content of 1.
The & val in line 6 is a reference. After the val variable declares and initializes memory, we can reference the memory address of the variable directly by using the address operator before the variable name.
In line 8, we once again use the * operator to value the pointer to directly get the data in the memory address that the pointer points to. Because the type declared by the pointer is int, the value fetched is the int value stored at the memory address that the pointer points to.
Pointers and arrays
# include
Int main ()
{
Intmyarray [4] = {1, 2, 3, 0}
Int * ptr = myarray
Printf ("ptr address =% ld, value * ptr=%d\ n", ptr,*ptr)
Ptr++
Printf ("ptr address =% ld, value * ptr=%d\ n", ptr,*ptr)
Ptr++
Printf ("ptr address =% ld, value * ptr=%d\ n", ptr,*ptr)
Ptr++
Printf ("ptr address =% ld, value * ptr=%d\ n", ptr,*ptr)
}
The array of C language represents a contiguous memory space that is used to store multiple objects of a particular type. In contrast, pointers are used to store a single memory address. Arrays and pointers are not the same structure and therefore cannot be converted to each other. The array variable points to the memory address of the first element of the array.
An array variable is a constant. You cannot assign a pointer to an array variable even if it points to the same address or to a different array. Nor can you assign one array variable to another array. However, it seems puzzling that an array variable can be assigned to a pointer. When you assign an array variable to a pointer, you actually assign the address to the first element of the array to the pointer.
Pointer and structure
# include
Struct person {
Intage
Char * name
}
Int main ()
{
Struct person first
Struct person * ptr
First.age = 21
Char * fullname = "fullname"
First.name = fullname
Ptr= & first
Printf ("age=%d, name=%s\ n", first.age, ptr- > name)
}
# include
# include
# include
# include
< string.h># include
< stdlib.h>Main ()
{
Int count,*array; / * count is a counter, and array is an integer pointer, which can also be understood as pointing to the first address of an integer array * /
If ((array= (int *) malloc (10*sizeof (int) = = NULL)
{
Printf ("storage space could not be allocated successfully.")
Exit (1)
}
For (count=0;count
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.