I know what a pointer is and how to use it, and also pass it through function parameters. And I recently found out about references they're called? For example:
It's similar to a pointer, but not as useful, but doesn't need to be dereferenced. Other than that, why would you use it instead of a pointer?Code:int& ref = some_variable;
Also, I've seen this, which is really confusing me: int*& var, for example, usually as a function parameter. What does *& mean? What is it doing or taking as a parameter. Also, usually when I see it, a normal variable is being passed into the function. And when assigned a value, it's assinged the memory address of. I'm confused what this is and what's happening. Any idea? Also, when assigned this memory address, it's usually of a pointer to an array or struct. The memory of a value in the array or a struct is the value assigned.
A sample code:
Code:int* an_array = new int[10]; int an_int; some_function(an_array, an_int); // Or would you pass &an_int or something? I've never actually // seen the function call, I just know that the variable to be // passed was a normal variable. void some_function(int* array, int*& something) { something = &array[1]; }



LinkBack URL
About LinkBacks


