我有以下结构,其中**座位成为顾客的二维数组。我想在将顾客安置在座位之前对此进行边界检查。 具体来说,如果座位是 2x2,并且我想知道如何检测合法插入并捕获出界;
theatre_seating *t;
t->seating[0][0]=some_patron; // how to know this is ok?
还有那个
t->seating[3][4]=some_patron; // how to know this is not?
结构。
struct patron {
char last_name[30];
char first_name[30];
};
struct theatre_seating {
struct patron **seating;
};
最佳答案
C 指针没有任何内置方法来跟踪它们所指向内容的大小。程序员(即您)必须实现某种存储方式。一种方法是将 rows
和 seats_per_row
变量添加到 theatre_seating
结构中,然后在使用时检查它们。
关于c - 嵌套二维结构数组的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52195013/