8.1 指针的基本概念和用法

p的类型为(int *)类型,40000的类型为整型,因此需要在40000的前面加上(int *)进行强制类型转换。

&x的返回值为一个指针

char * p = &ch1;//p指向ch1的地址

* pc = ‘B’;//往pc所指向的一个字节的内容空间里面存放B,即ch1 = B;

*pc为pc所指向的内存空间一个字节的内容。

#include<iostream>
using namespace std;
int main()
{
	char ch1 = 'A';
	char *pc = &ch1;
	cout << *pc;//A 
	return 0;
}
#include<iostream>
using namespace std;
int main()
{
	char ch1 = 'A';
	char *pc = &ch1;//pc指向ch1的地址 
	*pc = 'B';//ch1='B'
	cout << *pc << " " << ch1 << endl; // B B 
	return 0;
}

猜你喜欢

转载自blog.csdn.net/yanyanwenmeng/article/details/81121530
8.1