Could somebody explain to me why the ints
that are taken in from the user with scanf()
are stored in addresses that are 8h
apart even though the size of an int
on my 64 bit machine in 4 bytes? It is to with with alignment in memory?
#include <stdio.h>
void main() {
int *a;
int i, n;
printf(" Input the number of elements to store in the array : ");
scanf("%d",&n);
printf(" Input %d number of elements in the array : \n",n);
printf("size of on int is %d\n", sizeof(i));
for(i=0;i<n;i++) {
printf(" element - %d : ",i+1);
printf("address of a is %p\n", &a+i);
scanf("%d",a+i);
}
return 0;
}
Input the number of elements to store in the array : 3
Input 3 number of elements in the array :
size of on int is 4
element - 1 : address of a is 0x7ffda5cf8750
6
element - 2 : address of a is 0x7ffda5cf8758
5
element - 3 : address of a is 0x7ffda5cf8760
2