c - 二维数组问题

标签 c arrays

我需要制作一个二维数组,其中一列存储某个结构的指针,另一列存储一个 32 位魔数(Magic Number)。 我怎样才能在二维数组中做到这一点。? 或任何其他方法来跟踪这两列信息?

最佳答案

您可以使用:

// The struct that will hold the pointer and the magic number
struct data {
    void *other_struct_ptr;
    unsigned int magic_number;
};

// Declare my array
struct data array[N];

其中 N 是数组的大小。现在只需将您的数据填充到数组中。例如:

array[0].other_struct_ptr = NULL; // I used NULL for simplicity
array[0].magic_number = 0xDEADC0DE;
array[1].other_struct_ptr = NULL;
array[1].magic_number = 0xCAFEBABE;

关于c - 二维数组问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6978102/

相关文章:

c - 等待信号 (POSIX)

c 客户端使用 libwebsockets 调用 ibm-watson api

c - 使用 readline 防止回车输出

c - 在数组中使用 int 还是 char?

php - 将 array_map 应用于数组的列

jquery - 如何将整数数组从 asp.net mvc Controller 操作传递回 jquery 函数

c++ - 将数据写入数组时写访问冲突

c - 如何在 C 中优化这段代码

javascript - 从数组中获取数据

c++ - 可变大小的对象可能未被初始化