📄 reffunc.cpp
字号:
/*
reffunc.cpp. An example of using reference
functions as lvalues.
*/
#include <stdio.h>
#include <iostream.h>
int IntArray[] = {1, 2, 3};
#define SIZE (sizeof(IntArray)/sizeof(int))
int& RefFunc(int x);
int main ()
{
int x;
cout << "Before Reference Function: " << endl;
for (x = 0; x < SIZE; ++x)
{
cout << "IntArray[" << x << "] = ";
cout << IntArray[x] << endl;
}
for (x = 0; x < SIZE; ++x)
RefFunc(x) = x * 42;
cout << endl << "After Reference Function: " << endl;
for (x = 0; x < SIZE; ++x)
{
cout << "IntArray[" << x << "] = ";
cout << IntArray[x] << endl;
}
return (0);
}
//
// Return a reference to the array member indexed by
// parameter.
int& RefFunc (int x)
{
return (IntArray[x]);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -