fig05_20.cpp
来自「经典vc教程的例子程序」· C++ 代码 · 共 40 行
CPP
40 行
// Fig. 5.20: fig05_20.cpp
// Using subscripting and pointer notations with arrays
#include <iostream.h>
int main()
{
int b[] = { 10, 20, 30, 40 };
int *bPtr = b; // set bPtr to point to array b
cout << "Array b printed with:\n"
<< "Array subscript notation\n";
for ( int i = 0; i < 4; i++ )
cout << "b[" << i << "] = " << b[ i ] << '\n';
cout << "\nPointer/offset notation where\n"
<< "the pointer is the array name\n";
for ( int offset = 0; offset < 4; offset++ )
cout << "*(b + " << offset << ") = "
<< *( b + offset ) << '\n';
cout << "\nPointer subscript notation\n";
for ( i = 0; i < 4; i++ )
cout << "bPtr[" << i << "] = " << bPtr[ i ] << '\n';
cout << "\nPointer/offset notation\n";
for ( offset = 0; offset < 4; offset++ )
cout << "*(bPtr + " << offset << ") = "
<< *( bPtr + offset ) << '\n';
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?