ex0801.cpp
来自「practice c++, it is from the book http:/」· C++ 代码 · 共 39 行
CPP
39 行
// 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 + =
减小字号Ctrl + -
显示快捷键?