macro.cpp

来自「C++ Primer(第三版)的随书源代码」· C++ 代码 · 共 31 行

CPP
31
字号
// Section 10.1
// $ CC macro.cpp 

/*

  elem_cnt : 5    expecting: 10

*/

#include <iostream>
using std::cout;
using std::endl;

#define min(a,b) ((a) < (b) ? (a) : (b))

const int size = 10;
int ia[size];

int main() {
        int elem_cnt = 0;
        int *p = &ia[0];

        // count the number of array elements
        while ( min(p++,&ia[size]) != &ia[size] )
                ++elem_cnt;

        cout << "elem_cnt : "   << elem_cnt
             << "\texpecting: " << size << endl;
        return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?