[q] array pointer in tree Branch() definition

Hello,

This could be a novice c++ question (as I seem to forgot
basic C grammar).

PLease see “tree2.C” example in the tutorial
root.cern.ch/cgi-bin/print_hit_b … ee2.C.html
I see someone define an array variable like this way

t2.Branch(“vect”, &gstep.vect,“vect[7]/F”);

instead of

t2.Branch(“vect”,gstep.vect,“vect[7]/F”);
as shown in the tree2.C tutorial.

I think it should be w/o “&” as an array name itself is
already a pointer to the array, but somehow "&array_name"
also seems to work. Can anyone explain why this works?
and which one is correct way?

My question can be simply why “array_name”,
"&array_name[0]", and “&array_name” give the
same pointer? e.g.
{
#include
int a[10];
printf("%p, %p, %p\n", a, &a[0], &a);

}

I thought that “a” and “&a[0]” are correct but “&a” is not.
But “&a” seems to be also a correct in C/C++?

Regards,
Chul Su

At the URL indicated, I do not see the line with &. The line setting the branch address is correct and identical to the line in the tutorials

t2.Branch("vect",gstep.vect,"vect[7]/F");

Of course, all your other observations are correct

Rene

Hello,

I may have confused you, I was trying to show someone was
using “&” in front of array name. Yes the example on the
web (tree2.C) is correct.

Then, both w/ and w/o “&” in front of an array_name
are correct in Branch() call?
(I thought “&array_name” is not correct way in C language).

Thanks,
Chul Su