Greg Peckory Greg Peckory - 11 months ago 46
C Question

Why can function parameter contain addresses or variables in C

Looking up some tutorials online I noticed two different MPI_SEND uses:

The first says the start of the buffer is


MPI_Send(&a[500], 500, MPI_INT, 1, 0, MPI_COMM_WORLD);

The second says the start of the buffer is

MPI_Send(b, 500, MPI_INT, 0, 0, MPI_COMM_WORLD);

I'm very new to
so maybe it has something to do with pass by reference / value.

My guess is that
is the same as
, but in the first case swe use
because we are starting with an address in the middle of an array??

But why can't you just say
instead of

Answer Source

The term &a[500] is the address of a[500], that is the 500st element of the array a. So it is a pointer.

The term b can be either an array (e.g. int b[1000]) in which case, without index, it is converted to the pointer to the start of the array (i.e. &b[0] ), or a p real pointer, pointing to the start of some array.

Remarks: a[500] (without the ampersand) would be the value of the 500st element.