In the below code,
#include<stdio.h>
int main(){
char array[] = {'1', 2, 5.2};
char* my_pointer = array[2];
printf("%c", *my_pointer);
}
5.2
is stored in IEEE 754 representation in memory, char
picks 8 bits(first) from this float representation, due to little endian format.
C is a loosely typed language. Am allowed to cast float
to char
.
Why the program is core dumped?