I used the following code to find the difference between the address of two consecutive blocks of memory in an array. Although the printed size of each item('int' here) is 4, the difference between the address of two consecutive blocks containing that item turns out to be 1. Shouldn't the difference be 4?
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
int a[10];
for(int i=0;i<10;i++)
cin>>a[i];
cout<<"size of 1 block = "<<sizeof(int)<<"\n";
for(int i=1;i<10;i++){
// cout<<"Difference between address of consecutive memory blocks\n";
cout<<" "<<&(a[i])- &(a[i-1])<<"\n";
}
return 0;
}
Output
size of 1 block = 4
1
1
1
1
1
1
1
1
1