Those are two fragments of code, obviously not written by me but I'm trying to understand if they are examples of pointers. The C++ book I'm reading describes pointers with astericks but in the book, they are in front of the name as opposed to after the data type.
the above fragment of code
it takes as input (a pointer of a pointer of a float called "input") and a (pointer of a pointer of a float called "ouput")
a pointer of a float "input0" sets itself equal to the first element of input which is a float array?
this is where I get lost. Shouldn't the correct code be
float *input0 = &input
because the float pointer "input0" is trying to set itself equal to the memory location of whatever input ultimately points to thus the ampersand to get the memory location of whatever input points to?
&input is the pointer to input (float ***).
input is input (float **).
input[i] is element i in the array pointed to by input (float *). input[i][j] is [element j in the array pointed to by [element i in the array pointed to by input]] (float).
thanks for all the help helios :-D
still trying to wrap my head around pointers
my understanding of the & was that it returns the memory address of whatever it is placed in front of
aka &X will return the memory address of whatever X is
since a pointer is merely a signpost and doesn't have a memory address, i would think that logically putting a & in front of a pointer would regress all the way to the bottom?
or am I sounding stupid about now?
my understanding aside, semantically speaking,
"&" gives you a pointer of whatever you put it in front of (be it a data type or another pointer)
"[0]" gives you whatever the pointer pointed to (whether it be a data type or another pointer).
since a pointer is merely a signpost and doesn't have a memory address, i would think that logically putting a & in front of a pointer would regress all the way to the bottom?
Can you rephrase that?
Another thing I'd like to point out is that *x and x[0] are equivalent expressions.
sure thing,
i'm guessing that pointer's don't have a memory address like data types do. To make an analogy, data types are say houses, some are 8 bits, some are more, etc. A pointer is just a signpost pointing you in a direction and thus don't take up any bits. So asking the pointer where it's memory address would result in it asking what it points to for it's memory address.
Or is my understanding incorrect as I suspect it is?
would **x be equivalent to x[0][0] and so on and so forth?
A pointer, like any object in memory, does have a memory address. Just because a pointer's purpose is to store other object's addresses it doesn't mean that the pointer itself doesn't have to be stored somewhere. To make it clearer to visualize, you could write a small program like this:
1 2 3 4
int a = 0;
int* pt = &a; // pt points to a
std::cout << "a's value: " << a << std::endl << "a's address: " << &a << std::endl;
std::cout << "pt's value: " << pt << std::endl << "pt's address: " << &pt << std::endl;