代码改变世界

指针运算

2022-11-15 22:27  钟铧若岩  阅读(15)  评论(0编辑  收藏  举报

 

 1 #include <iostream>
 2 using namespace std;
 3 int main()
 4 {
 5     int a =100;
 6     int *b = &a;
 7     char *c;
 8     char *d = "hello world";
 9     c = d;
10     cout << "a = " << a << endl;    //100
11     cout << "b = " << b << endl;    //0x7bffd
12     cout << "*b = " << *b <<endl;   //100
13     cout << "c = " << c <<endl;     //hello world
14     cout << "d = " << d <<endl;     //hello world
15     cout << "*c = " << *c <<endl;   //h
16     cout << "*d = " << *d <<endl;   //h
17     return 0;
18 }