I wrote a little program in C to explain how pointers work:
int main(){
char * pointer;
printf('%zu \n', sizeof(char));
printf('%zu \n', sizeof(signed short));
printf('%zu \n', sizeof(signed int));
printf('%zu \n', sizeof(float));
printf('%p \n',((char*)(pointer) + 10 * 5));
printf('%p \n',((signed short*)(pointer)) + 10 * 5);
printf('%p\n',(((signed int*)(pointer)) + 10 * 5));
printf('%p\n',((float*)(pointer)) + 10 * 5);
}
1
2
4
4
0x7fff5fc01084
0x7fff5fc010b6
0x7fff5fc0111a
0x7fff5fc0111a"
char * pointer;
printf('%zu \n', sizeof(char));
printf('%zu \n', sizeof(signed short));
printf('%zu \n', sizeof(signed int));
printf('%zu \n', sizeof(float));
printf('%p \n',((char*)(pointer) + 10 * 5));
printf('%p \n',((signed short*)(pointer)) + 10 * 5);
printf('%p\n',(((signed int*)(pointer)) + 10 * 5));
printf('%p\n',((float*)(pointer)) + 10 * 5);
}
1
2
4
4
0x7fff5fc01084
0x7fff5fc010b6
0x7fff5fc0111a
0x7fff5fc0111a"
No comments:
Post a Comment