Question
/* * ReferenceDemo.cpp * * Modified by Yang Peng on 12/31/17 */ #include #include #include using namespace std; void refIncrement(int& a) { a++; } void
/*
* ReferenceDemo.cpp
*
* Modified by Yang Peng on 12/31/17
*/
#include
#include
#include
using namespace std;
void refIncrement(int& a)
{
a++;
}
void onePlus(int a)
{
a++;
}
struct Pair
{
string name;
int val;
};
vector
int& value(const string& s)
{
for (int i=0; i if (s == pairs[i].name) return pairs[i].val; } Pair p = {s, 0}; pairs.push_back(p); return pairs[pairs.size()-1].val; } int main() { int i = 1; int& r = i; int x = r; cout cout r = 2; cout int& xr = x; cout cout onePlus(i); cout onePlus(r); cout onePlus(x); cout cout refIncrement(i); cout refIncrement(r); cout refIncrement(x); cout cout value("aa")++; value("bb")++; value("bb")++; value("aa")++; value("aa")++; value("bb")++; value("aa")++; value("aa")++; for (int i=0; i cout } return 0; } Output:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started