-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest2.cpp
47 lines (34 loc) · 938 Bytes
/
test2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// TODO (Root#1#):
//const char * <==> char const * 指向const char类型对象的指针 ...
//
//char * const 指向char类型的const指针
#include <iostream>
#include <cstring>
using namespace std;
typedef char * mytype;
int main()
{
const char *str1 = "hello";
const char *str2 = "world";
const char *p1 = str1;
cout << p1 << endl;
p1 = str2;
cout << p1 << endl;
cout << "========= p1 ========" << endl;
//char *const str3 = "mytest";
char *const p2 = (char *const )"the";
cout << p2 << endl;
// p2 = "change";
// cout << p2 << endl;
cout << "========= p2 =========" << endl;
char const *p3 = str1;
cout << p3 << endl;
p3 = str2;
cout << p3 << endl;
cout << "========== p3 ========" << endl;
const mytype p4 = (char * const )"P4";
cout << p4 << endl;
// p4 = (char * const)"p000000000000";
cout << "========== p4 =========" << endl;
return 0;
}