Arithmetic of pointers in C

2

I'm doubtful of a way to know the length of a vector without using sizeof :

int n = *(&arr + 1) - arr;

It is known that:

arr is of type int ( * ) and (&arr + 1) is of type int ( * )[size] .

What is the function of * ?

Is it to get the value of the address (&arr + 1) or to make a cast from int ( * )[size] to int ( * ) ?

    
asked by anonymous 13.11.2018 / 03:01

1 answer

2

The * (star or star) operator is always used to "derrefer" an address, or either, it takes the value that is in that address, nothing more than this, nothing has to do with cast . To tell you the truth, I do not know what the rest of the question is all about, so confused.

Here the operator & returns a reference ( arr is already a reference), you have the reference of the reference, when doing the dereference is only with a reference.

    
13.11.2018 / 03:15