Let's say you have the code as follows:
float arr[] = {
0.0f,
1.0f,
62.0f,
400.0f
};
Then I print this out as follows:
printf("%lu\n", sizeof(0[arr]));
Why does it return 4, and what is happening here?
Let's say you have the code as follows:
float arr[] = {
0.0f,
1.0f,
62.0f,
400.0f
};
Then I print this out as follows:
printf("%lu\n", sizeof(0[arr]));
Why does it return 4, and what is happening here?
Copyright © 2021 Jogjafile Inc.
From the C Standard (6.5.2.1 Array subscripting)
So this expression
0[arr]is equivalent to the expressionarr[0].The only difference is relative to how the subscript operator is defined in the C grammar.
It is defined like
So for example
++i[arr]is not the same asarr[++i]. The first expression is equivalent to++( i[arr] ). While this expressioni++[arr]is equivalent toarr[i++].Here is a demonstration program.
The program output is