references in c++
#include <vector>
void simple_reference_example() {
int x;
int &y = x; // y refers directly to x.
x = 10;
std::cout << y; // prints 10
}
/* careful! edits to d in this function affect the original */
void pass_by_ref(std::vector<int> &d) {
d[0] = 10;
}
/* 'const' prevents changing of data in d */
void pass_by_const_ref(const std::vector<int> &d) { }
int main(){
std::vector<int> data(1, 0); // initialize 1 element vector w/ the value 0
pass_by_ref(ints);
std::cout << data[0]; // prints 10
pass_by_const_ref(ints);
}