pr06029.cpp

来自「c++编程宝典源码及Quincy99编译器 是《标准C++编程宝典》电子工业出」· C++ 代码 · 共 50 行

CPP
50
字号
////////////////////////////////////////
// File Name: pr06029.cpp
////////////////////////////////////////
#include <iostream>

// A big structure.
struct bigone
{
    int serno;
    char text[1000];
};

// Two function prototypes with a structure parameter.
void slowfunc(bigone p1);    // Call by value.
void fastfunc(bigone& p1);   // Call by reference.

////////////////////////////////////////
// The main() function.
////////////////////////////////////////
int main()
{
    static bigone bo = {123, "This is a BIG structure"};

    // This call will take a while.
    slowfunc(bo);

    // This call will be faster than the previous one.
    fastfunc(bo);

    return 0;
}

////////////////////////////////////////
// A call-by-value function.
////////////////////////////////////////
void slowfunc(bigone p1)
{
    std::cout << p1.serno << std::endl;
    std::cout << p1.text << std::endl;
}

////////////////////////////////////////
// A call by reference function.
////////////////////////////////////////
void fastfunc(bigone& p1)
{
    std::cout << p1.serno << std::endl;
    std::cout << p1.text << std::endl;
}

⌨️ 快捷键说明

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