Go Down

Topic: reference and deference help (Read 754 times) previous topic - next topic

winner10920

Hey I've never used reference or deference before and I've read a bit and it just boggles my mind unfortunately
I want a function to read an outside array and to return the modified array
im pretty sure the way to do this is to have the function first be pointed to the array, then modify it, I don't exactly know how this looks like since what I've read doesn't really show that and I can't put 2 and 2 together to see it, atleast for now
But I also can't figure out how to return an entire new array or replace the original one with the modified

winner10920

I didn't try it but here's what I have for say a single int

Shift(&number); //give deference or location of number

Shift(int address){
Int variable = *address; //stores the value of number to variable
//do work on variable
&address = variable; //puts variable back in place of number so when number is used it has the modification
}

Is that correct? And can I use it to modify an entire array? Is there a way to just skip all this and return an array?

winner10920

Or maybe someone know an easier way of what im trying to do,
im trying to make functions to flip,shift,or rotate an 8x8 array for a matrix, im trying to do it myself but if someone knows a shortcut I wont mind XD

James C4S

Instead of returning an array, make an argument of your function a pointer to the new array.

Think of how sprintf() works.  You have to give it a buffer in the function call, it doesn't "return" anything.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

ajofscott

&variableName is an object REFERENCE to the Class that variableName is an instance of. Members are then accessed via dot syntax ex. variableName.function().
Whereas *variableName is a pointer to the location where variableName's value resides(memory location), if variableName is a class then member functions are accessed like this variableName->function().

Go Up