📄 ex0801.cpp
字号:
// Programming with C++, Second Edition, by John R. Hubbard
// Copyright McGraw-Hill, 2000
// Example 8.1 on page 184
// Using pointer variables
#include <iostream>
using namespace std;
int main()
{ int n=44; // n holds the int 44
cout << "int n=44; // n holds the int 44:\n";
cout << "\t\t n = " << n << endl;
cout << "\t\t &n = " << &n << endl;
int* pn=&n; // pn holds the address of n
cout << "int* pn=&n; // pn holds the address of n:\n";
cout << "\t\t n = " << n << endl;
cout << "\t\t &n = " << &n << endl;
cout << "\t\t pn = " << pn << endl;
cout << "\t\t &pn = " << &pn << endl;
cout << "\t\t *pn = " << *pn << endl;
*pn = 77; // changes the value of n to 77
cout << "*pn = 77; // changes the value of n to 77:\n";
cout << "\t\t n = " << n << endl;
cout << "\t\t &n = " << &n << endl;
cout << "\t\t pn = " << pn << endl;
cout << "\t\t &pn = " << &pn << endl;
cout << "\t\t *pn = " << *pn << endl;
int* q=&n; // q also holds the address of n
cout << "int* q=&n; // q also holds the address of n:\n";
cout << "\t\t n = " << n << endl;
cout << "\t\t &n = " << &n << endl;
cout << "\t\t pn = " << pn << endl;
cout << "\t\t &pn = " << &pn << endl;
cout << "\t\t *pn = " << *pn << endl;
cout << "\t\t q = " << q << endl;
cout << "\t\t &q = " << &q << endl;
cout << "\t\t *q = " << *q << endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -