我正在尝试获取字节和指针以及它们的存储方式,任何人都可以解释或回答我的一些问题。谢谢
int num = 513; <-- allocating a 4 bit memory by initializing
//[01][02][00][00] <-- (numbers are sorted and shown as litle endian)
char * ptr = # //char is (one byte)
↓
//[01][02][00][00]
// pointer always start from the [0] (as in this array byte length)
// in the allocated address in the memory ptr[0] is in this case = [01]
// (printed as %x02 "printf("the byte %02x\n",ptr[0]);" - if it's only
//single number 1 a zero will be added on the length so it prints out as 01)
int * ptr = # //now creating a pointer with the type of int (four bytes)
↓ ↓ ↓ ↓
//[01][02][00][00]
- 我怎样才能访问这个 int 指针的第一个字节?[问题01]
- 有没有办法查看第一个字节([01])内部的咬痕?[问题02]
- 指针在哪里保存地址?它是否必须在 ram 中分配一个内存空间来保存地址,例如 0x233828ff21,如果是这样,这个(0x233828ff21)地址需要很多字节?[问题03]
- 这个 int 指针在哪里存储它的类型长度(4 字节)?[问题05]
- 如果我声明具有更长字节内存分配的类型,例如
long long * ptr = #
[01][02][00][00][00][00][00][00] 会发生什么,因为我将 long long 指向 4 字节 int ,最后这 4 个是否已经被另一个程序分配并正在使用中?我可以读吗?[问题06] - 二进制只有 0 和 1,其中一个(0 或 1)是否称为咬?[问题07]
- 一个字节是8位对吗?为什么我在转换本网站(https://www.rapidtables.com/convert/number/decimal-to-binary.html)中的数字1时得到16位0000000000000001不应该是8?[问题08]