#include<iostream>
using namespace std;
int main() {
int buf[2];
buf[0]=65,buf[1]=66;
char *p=(char*)(&buf[0]);
for(int i=0;i<8;i++)
cout<<(int)*(p+i)<<" ";
return 0;
}
I was trying to understand the memory allocation using above code. The output of the above code is:
65 0 0 0 66 0 0 0
Why are all the values 0 except for 'p' and 'p+4', when 'p+1', 'p+2','p+3' represent the 1st integer block containing 65 and 'p+5', 'p+6','p+7' represent the 2nd integer block?
Please correct me if I'm wrong.