ex0710.cpp
来自「《C++编程习题与解答》书中所有例题与习题的源代码」· C++ 代码 · 共 24 行
CPP
24 行
// Programming with C++, Second Edition, by John R. Hubbard
// Copyright McGraw-Hill, 2000
// Example 7.10 on page 163
// Traversing an array with as pointer
#include <iostream>
using namespace std;
int main()
{ const int SIZE = 3;
short a[SIZE] = {22, 33, 44};
cout << "a = " << a << endl;
cout << "sizeof(short) = " << sizeof(short) << endl;
short* end = a + SIZE; // converts SIZE to offset 6
short sum = 0;
for (short* p = a; p < end; p++)
{ sum += *p;
cout << "\t p = " << p;
cout << "\t *p = " << *p;
cout << "\t sum = " << sum << endl;
}
cout << "end = " << end << endl;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?