C ++ - What happens when you index an array using float?

I am trying to understand what happens when indexing through an array with a float value.

This link: Float Values ​​as an index in an array in C ++

Does not answer my question, as it claims that the float should be rounded to an integer. However, in the code I'm trying to evaluate, this answer does not make sense, since the index value will always be only 0 or 1.

I am trying to solve a coding problem sent by Nintendo. To solve the problem, there is an archaic instruction that uses bitwise assignment in an array using a long complex bitwise expression.

An array is declared as a pointer

unsigned int* b = new unsigned int[size / 16]; // <- output tab

Then it assigns 0 to each element.

for (int i = 0; i < size / 16; i++) {   // Write size / 16 zeros to b
    b[i] = 0;
}

Here is the beginning of the instructions.

b[(i + j) / 32] ^= // some crazy bitwise expression

.

, . , , .

, float, int. .

+4
3

float. size - , 16 - , , , size/16 .

, , size [0,16), size/16 == 0. size [16,32), size/16 == 1 .. size (-16, 0], size / 16 == 0.

([x,y) - "" x y: x y, x, y)

+8

- . :

class A {...}; 
A ar[17]; 
std::cout << ar[3] << std::endl;

ar[3] :

*(ar + 3); 

, ar[3.4] ,

*(ar + 3.4)    (1)

++ 5.7.1 - , :

(...) , , .

(1) .

, float,

+3

:

#include <stdio.h>
int main(int argc, char** argv) {
  int x[5];

  int i;
  for (i = 0; i < 5; ++i)
    x[i] = i;


  x[2.5] = 10;

  for (i = 0; i < 5; ++i)
    printf("%d\n", x[i]);
}

gcc, :

foo.c:10: error: array subscript is not an integer
+2

All Articles