一级指针.

指针(地址的别名)
指针变量
地址变量

元素访问:
*p->解引用  简介访问符
类型 -> 定义指针变量
*变量名-> 解引用

数组->指针
数组名+整型:
arr->数组首元素地址
数组名+1->加单元格(类型有关)
*(arr+1)<=>arr[1]
*arr<=>arr[0]
p+3;p向右移动3个单元格:12字节

指针和const的使用
const int *p=&a;//int const *p=&a;
int* const p= &a;
(1)
int a=10;
const int*p=&a;->不能修改指向变量的值
*p=100;//error
p=&b;//right
*p=200;//error
(2)
int a=10,b=20;
int *const=&a;->修饰指针变量本身,一经指向a,不能指向其他地址。没有限定a本身的值是否被修改
p=&b;//error
*p=100;//right
(3)
const int a=10;//a是常量
int*p=&a;//error         *p=10;error
const int*p=&a;//right
(4)
const int* const p=&a;//p指向a,不能指向其他变量。p不能修改a的值
字符串:定义
1)char ch[]="hello";数组大小为5+1''
2)char *p="hello";   //error
const char*str="hello";   //right4
字符串1=:"hello"    字符串2 ="world"  关系
1)字符串拷贝     
2)字符串拼接操作
3)字符串比较操作
4)字符串“123”->整型123“-123”->-123"+-+----123"->"-123"
atoi操作
5)itoa      整形数字:123->"123"整型:-123->“-123”
面试题:“i am student”->空格替换:1个空格字符被替换为2个‘#’变为"i##am##a##student"

const int*p=&a
p->a常量
字符串:
char arr[]={'h','e','l','l','o'};
arr->sizeof(arr)sizeof(arr[0]);
strlen(arr);
数组和指针的关系:(p+i)<==>&p[j]
const char*str="hello";
*(str+i)='z';
*(str+i)->str[i];
指针形式操作
strcat()

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码
< <上一篇
下一篇>>