I did this simple function to print the content of an array of int.
void print_array(int size, int array[size])
{
printf("{");
for (int i = 0; i < size - 1; i++)
{
printf("%d, ", array[i]);
}
printf("%d}\n", array[size - 1]);
}
It seems to work fine with examples. However, while using it to debug a function, I got the result :
{-1, 0, 1, 2, 3, 4, 16, 17, 18, 8, 0, 1, 11, 12, 13, 14, 15, 27, 28, 9, 30, 31, 21, 24, 14, 24, 25, 26, 27, 19, 31, 41, 33, 23, 33, 34, 35, 27, 28, 29, 50, 808779818, -363075840, -202888522, 45, 46, 0, 0, -1377617600, 32767, -1377617208, 32767, 2055390135, 22066, 2055404888, 22066, 448540736, 32670, 446392223, 32670, 16, 48, -1377617632, 32767, -1377617824, 32767, -363075840, -202888522, 448540736, 32670, 32670, 0, 284, 0, 1, 0, 0, 0, -1377617929, 32767}
As you can see, some of the numbers here are too big to be printed as int, even though I used the %d identifier in the printf function. Can someone explain to me what happens here ? When I'm testing the equality of this array with the good answer, the test happen to be true (???).
I tried understanding it by doing
int a = 808779818;
int b = 42;
assert(a == b);
but there the assert fails.
You can easily check what is maximum and minimum integer value in your system:
https://godbolt.org/z/az7nd8fEP
From man pages:
And it is expected result as
808779818 != 42