reference variablesr in c++
Value of i : 5
Value of i reference : 5
Value of d : 11.7
Value of d reference : 11.7
reference variablesr in c++
Value of i : 5
Value of i reference : 5
Value of d : 11.7
Value of d reference : 11.7
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);
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us