#include <stdio.h>
#define max_size 100
float array[max_size];
int n,counter;
int main(){
printf("Enter the size of the array...\n");
scanf("%d",&n);
for (counter=0; counter<n; counter++){
printf("%p\t",&array[counter]);
}
printf("\n\n");
return 0;
}
I am just experimenting with this C program and I am trying to verify that the size of a float is 8 bytes. But upon running this code with 5 elements in array, I get the address of these elements as following:
Enter the size of the array...
5
0x555555755040 0x555555755044 0x555555755048 0x55555575504c 0x555555755050
As you can see for the first float number, my system has allocated memory space ...40,41,42,43 which is 4 bits of space if I am not wrong. But the float data type is supposed to have 8 bytes of space for it. I am thinking that the program should have allocated memory space ...40,41,...4F for 2 bytes of space. So
...40-...4F //for first 2 bytes
...50-...5F //for second 2 bytes
...60-...6F //for third 2 bytes
...70-...7F //for last 2 bytes
So the second address would start at ...80. But this is not the result I am obtaining. What am I missing in this process? Thank you for the help !!