【发布时间】:2018-10-21 07:04:26
【问题描述】:
课本里面有一些代码和解释
#include <stdio.h>
typedef int *byte_pointer;
void show_bytes(byte_pointer start, size_t len){
int i;
for(i=0; i<len; i++)
printf(" |%.2x",start[i]);
printf("\n");
}
void show_int(int x){
show_bytes((byte_pointer) &x, sizeof(int));
}
它说引用 start[i] 表示我们要读取 i 位置 超出 start 指向的位置的字节。
(例如 int 类型)指针具有 int 类型(4 字节)是否正确,因此它读取 4 字节(例如地址 0x100~0x103)或数据结尾 即使我们只是给出一个起点地址(例如0x100)?我说的对吗?
【问题讨论】:
-
我什么都不懂。请不要 typedef 指针。
-
如果此代码是从您的教科书中逐字提取的,您应该要求退还您的学费。
-
int不是一个字节。除了混淆代码之外,typedef 还在对阅读它的人撒谎。
标签: c arrays pointers reference memory-address