pointer
Advanced pointer
- Character pointer
- Array pointer
- Pointer array
- Parameter passing pointers and arrays of mass participation
- Function pointer
- Array of function pointers
- Pointer to an array of function pointers
- Callback
- Pointers and arrays resolve questions
In the initial stage of the pointer which, we know that the concept of pointers
- Pointer is a variable used to store address, address uniquely identifies a memory space
- Size of a pointer is fixed 4/8 bytes (32-bit or 64-bit platform internet)
- There is a pointer type, pointer type determines the pointer integer + step, dereferencing operation authority time
- Pointer calculation (± pointer integer, pointer - the pointer, pointer arithmetic comparison)
Character pointer
#include<stdio.h>
int main()
{
char a = 'w';
char* pc = &a; //这个时候,pc称为字符指针,pc的类型为char*
char arr[10] = "abc";
char* pa = arr; //arr作为数组名,他代表的是数组首元素的地址,pa的类型为char*
char* p = "abcdef"; //此时p只具有4个字节,但是abcdef不算\0有6个字节,显然放不下
//那么此时,p中存的就是"abcdef"中首个字母a的地址,地址用指针接收,刚好为4个字节
//上述常量表达式的结果就是首字符a的地址。
}
topic:
#include<stdio.h>
int main()
{
char arr1[] = "abcdef";
char arr2[] = "abcdef";
if (arr1 == arr2)
printf("arr1==arr2\n");
else
printf("arr1!=arr2\n");
return 0;
//打印结果为arr1!=arr2
//原因:因为arr1和arr2会开辟两块空间的大小,虽然都表示的是首字母a的地址
//但是两块空间的地址是不一样的,所以两块空间中a的地址自然也就是不一样的了。
}
#include<stdio.h>
int main()
{
char* p1 = "abcdef";
char* p2 = "abcdef";
if (p1 == p2)
printf("p1==p2");
else
printf("p1!=p2");
return 0;
//打印结果为p1==p2
//虽然把字符串abcdef地址存在了p1和p2当中,但是两个字符串是一样的
//都是abcdef,所以首元素a的地址自然也是一样的了
//abcdef为常量字符串,所以说他是不能被改变的,其实也只会出现一次abcdef
//但是p1的地址和p2的地址是绝对不一样的。
}