What does mean ARR in the half place in C?

60 Views Asked by At

I have code :get_transaltion(&(arr[1/2]) ) The array is of structures that each contain an array of 3 places, which places does the function accept?

I edited the array in the first place in the structure with an array of 3 places and I didn't get what I edited

struct vector { 
  float data[3]; 
};
arr[1 / 2u].data[0] = 1 + 0.1;
arr[1 / 2u].data[1] = 1 + 0.2;
arr[1 / 2u].data[2] = 1 + 0.3;
2

There are 2 best solutions below

0
Harith On BEST ANSWER

The result of the / operator is the quotient from the division of the first operand by the second.

Here:

arr[1 / 2u].data[0] = 1 + 0.1;

1 / 2u evaluates to 0. So it's equivalent to writing:

arr[0].data[0] = 1 + 0.1;
0
Vlad from Moscow On

All these statements

arr[1 / 2u].data[0] = 1 + 0.1;
arr[1 / 2u].data[1] = 1 + 0.2;
arr[1 / 2u].data[2] = 1 + 0.3;

are equivalent to

arr[0].data[0] = 1 + 0.1;
arr[0].data[1] = 1 + 0.2;
arr[0].data[2] = 1 + 0.3;

because due to the integer arithmetic the expression 1 / 2u is equal to 0.

As for this function call

get_transaltion(&(arr[1/2]) )

then it is equivalent to

get_transaltion(&(arr[0]) )

That is a pointer to the first element of the array is passed to the function.