Ino
Ino

Reputation: 21

What does mean ARR in the half place in C?

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;

Upvotes: 0

Views: 58

Answers (2)

Vlad from Moscow
Vlad from Moscow

Reputation: 311146

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.

Upvotes: 1

Madagascar
Madagascar

Reputation: 7345

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;

Upvotes: 1

Related Questions