c++笔记

1.指针的运算:
1.*:解析引用符,取指针指向的内容;
注意:1.乘法:a*b 2.定义*:指针 3.取内容:*指针变量
2.取内容的字节数 = sizeof(指向的类型);

//char* pch[3] = { "Hello", "Apple", "Monday" };
//cout << *pch[1] << endl;//A
//cout << pch << endl;//00DDFA34
//cout << *pch[2]**pch[1] << endl;//5005
//char* p = pch[1];
//cout << *p - **pch << endl;//-7
//cout << (int)p - (int)pch[2] << endl;//-8
//char** ppch = &pch[2];
//cout << *ppch << endl;//Monday
//cout << **ppch + 3 << endl;//80
//cout << (char)**ppch + 3 << endl;//80
//cout << (char)(**ppch + 3) << endl;//p
//cout << *pch[1] - **ppch << endl;//-12

//int n[5] = { 1, 2, 3, 4, 5 };
//int* p = n;
//cout << (*p)++ << endl;//n[0]++//1//n[0]=2
//cout << (int)&*p - (int)&n[1] << endl;//&n[0]//-4
//cout << n[0] << endl;//2
//int** pp = &p;
//cout << ++**pp << endl;//++n[0]//3//n[0] = 3
//p = &n[2];
//cout << --**pp << endl;//--n[2]//2//n[2]=2
//for (int i = 0; i < 5; i++)
//{
// cout << n[i] << endl;
//}

//cout << *pp << endl;// p
//cout << **pp << endl;// *p = n[2]
//cout << p << endl;
//cout << &n[2] << endl;


//char ch[] = "abcdefg";
//char* pch = &ch[2];
//cout << *pch << endl;//'c'
//cout << pch << endl;// "cdefg"
//cout << (*pch)++ << endl;//ch[2]++//'c'//ch[2]='d'
//cout << (int)pch - (int)ch << endl;//2
//char** ppch = &pch;
//pch = ch;
//cout << *ppch << endl;// "abddefg"
//cout << ++**ppch << endl;//++ch[0]//'b'//ch[0]='b'
//// &ch[0]
//cout << (int)(unsigned char)((int)*ppch - (int)&ch[4]) << endl;// 252
//cout << *pch - ch[3] << endl;// ch[0] - ch[3]//-2
//cout << ch << endl;//"bbddefg"

 


//int a = 0x12345678;
//// p指向a
//int* p = &a;
//// 取p指向的内容:a
//cout << hex << *p << endl;// 字节数 = sizeof(int)
//short* p1 = (short*)p;
//cout << *p1 << endl;// 字节数 = sizeof(short)

你可能感兴趣的:(c++笔记)