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 > Development >
Share
Shulou(Shulou.com)06/02 Report--
In this issue, the editor will bring you about how to understand the guidelines in the C language. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
1 what is the pointer
A pointer is an object in assembly language that uses an address to point to a value stored in another place in the computer memory. Since the desired variable unit can be found through the address, the address points to the variable unit. Therefore, the address image is called the pointer. It means that the memory unit with its address can be found through it.
Int main () {int a = 10 role / open up a space in memory int* p = & a politics / here we take out the address of the variable a, you can use the & operator / / to store the address of an in the p variable, p is a pointer variable. Return 0;}
The pointer is a variable, the variable in which the address is stored. (values stored in pointers are treated as addresses)
The size of the pointer is a fixed 4 stroke 8 bytes (32-bit platform / 64-bit platform)
2 pointers and pointer types
The pointer type determines the amount of space that can be accessed when the pointer is dereferenced.
Int*p; * p can access 4 bytes
Char*p; * p can access one byte
Double*p; * p can access 8 bytes
The type of pointer determines how far the pointer goes (the step size of the pointer), corresponding to the above.
3 wild pointer (1) three cases
1. Pointer not initialized
two。 Pointer out of bounds access
Int main () {int arr [10] = {0}; int* p = arr; int i = 0; for (I = 0
< 11;i++) {//当指针指向的范围超出数组arr的范围时,p就是野指针 *(p++) = i; } return 0;} 3.指针指向的空间释放 (2)如何规避野指针 指针初始化 小心指针越界 指针指向空间释放即使置NULL 指针使用之前检查有效性 4指针运算 指针 加减 整数 指针 减 指针 指针的运算关系 5指针和数组 整型数组,存放整型 字符数组,存放字符 指针数组,存放指针 int main() { int a = 10; int b = 20; int c = 30; int* arr[3] = { &a,&b,&c };//指针数组 int i; for (i = 0;i < 3;i++) { printf("%d\n", *(arr[i])); }}6字符指针 char*; 示例: int main() { const char* p = "abcdef";//"abcdef"是一个常量字符串 printf("%c\n", *p);//p是字符串"abcdef"的首元素a的地址 printf("%s\n", p); return 0;} 结果:7 array pointer
Storage array address
Int main () {/ / int * pairNull spare dial p is an integer pointer / / char* pc = NULL;//pc is a character pointer / / int arr [10] = {0}; / / arr first element address / / & arr [0] first element address / & arr array address int arr [10] = {1m 2pm 3pm 4e 5e 6e 7e 8e 9e 10} Int (* p) [10] = & arr;// [] has a higher priority than *, so use (). At this point p is the array pointer. The address of the storage array return 0;} 8 pointer array
An array of pointers is an array of pointers.
Int main () {int arr1 [] = {1meme 2pas 3pas 4pens 5}; int arr2 [] = {2pje 3pas 4pas 5pas 6}; int arr3 [] = {3pje 4pas 5pas 7}; int* parr [] = {arr1,arr2,arr3}; / / parr is the array pointer in which the array name (the address of the first element of the array) is put into it int I = 0; for (I = 0bot I < 3) Int +) {printf ("% d", * (parr [I] + j)) {printf ("% d", * (return [I] + j));} return 0;}
9 other
(1)
Int arr [10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int* p=arr
/ / arr [I] = * (arr+i) = * (pairi) = = p [I]
(2)
Int arr [5]; int * parr1 [10]; int (* parr2) [10]; int (* (parr3 [10])) [5]
Arr is an array of integers with five elements.
Parr1 is an array. The array has 10 elements, and each element is of type int*,parr1, which is the pointer array.
Parr2 is a pointer that points to an array of 10 elements, each of which is an int,parr2 pointer.
Parr3 is an array of 10 elements, each of which is an array pointer to an array of five elements, each of which is an int.
The above is the editor for you to share how to understand the pointer in the C language, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
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.