I ran through these few lines of code in C:
int tab[]={4,6,8,9,20};
char *p;
p=(char*)tab
And the question was how to print the value of 20 using the pointer p.
So i used a for loop to see what's going on with p
for(int i=0;i<20;i++){
printf("%d ",p[i]);
}
and i got this output:
4 0 0 0 6 0 0 0 8 0 0 0 9 0 0 0 20 0 0 0
i want to understand the logic behind those zeros appearing.
charandinthave different sizes? Do you know how numbers are stored in memory?intuses 4 bytes,charuses 1 byte. So you're seeing each of the 4 bytes in the numbers when you usep[i].int tab[]={0x04030201, 0x08070605, 0x0C0B0A09, 0x100F0E0D, 0x14131211};. What does your code print?