Is this pointer code?

Hi guys,
New to C++ so if my question is really stupid, please forgive me

static void metadata(Meta* m) {


virtual void compute (int count, float** input, float** output) {
float* input0 = input[0];
float* output0 = output[0];

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.

So it would be

float *input

instead of

float** input

Thank for any help.
C/++ is whitespace insensitive. int**, int **, int* *, and int * * all refer to the same type.
The way to read it is right to left:

float * pointer to float [base value is a float]

float * * pointer to (pointer to float) [base value is a (pointer to float)]

Dereferencing the pointers gives you the value base value.
Hence,

given float * x; then x[0] is a float (same as *x)

given float ** xs; then x[0] is a pointer to float (same as *x)

and x[0][0] is a float (same as **x)

Hope this helps.
thanks, that was a lot of help

A quick question on pointers

1
2
3
virtual void compute (int count, float** input, float** output) {
        float* input0 = input[0];
        float* output0 = output[0];


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?
No, pointers are just regular integers.
For example, although this is an unsafe conversion, you can do this:
1
2
3
int a=1024;
unsigned long a=(unsigned long)&a;
std::cout <<*(int *)a;

And you can also get the size of a pointer: sizeof(void *) /*data pointers may not be larger than this*/.

would **x be equivalent to x[0][0] and so on and so forth?
Yes. Also, *x[0].
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;
cool, that clears up my confusion

thanks a bunch guys
Topic archived. No new replies allowed.