In C, you can cast both simple data types like int, float, and pointers to these.
Now I would have assumed that if you want to convert from
Of course it does! Casting tells the compiler how to look at the some section of memory. When you then access the memory, it tries to interpret the data there based on how you told it look at it. It's easier to understand it using the following example.
int main()
{
char A[] = {0, 0, 0, 1 };
int p = *((int*)A);
int i = (int)*A;
printf("%d %d\n", i, p);
return 0;
}
The output on a 32-bit little endian machine will be 0 16777216. This is because (int*)A tells the compiler to treat A as a pointer to integer and hence when you dereference A, it looks at the 4 bytes starting from A (as sizeof(int) == 4). After accounting for the endian-ness, the content of the 4 bytes evaluated to 16777216. On the other hand, *A dereferences A to get 0 and (int)*A casts that to get 0.