我需要制作一个二维数组,其中一列存储某个结构的指针,另一列存储一个 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/