the above also outputs the number of bytes allocated to the float in the memory
No, size reports the size of ptr, which is a char *. You should do sizeof(num1) if you want the size of your float.
I get 22FF74 as my output
You're printing the value of ptr, which is the address of num1. Not the value of the float at all. What they meant was something more like this:
Code:
int main(void)
{
float num1;
char *ptr;
int size;
int i;
printf("Enter: ");
fflush(stdout);
scanf("%f", &num1);
ptr = (char *)&num1;
size = sizeof(num1);
printf("Float is %d bytes\n", size);
// Loop through each byte of the float by using the ptr
for(i = 0;i < size;++i)
printf("%02X ", *ptr++);
putchar('\n');
return 0;
}