Initialize a two dimensional array of pointer elements using memset
2 answers
typedef struct my_s {
int x;
int y;
} my_T;
typedef struct your_s {
my_T * x;
} your_T;
your_T array[MAX_COL][MAX_ROW];
You cannot initialize your_T pointers to null using memset, because it is not specified that a null pointer has its own bit pattern of zero bits. But you can create your array like this:
your_T array[MAX_COL][MAX_ROW] = {{}};
The elements will be initialized by default, which means the pointer indicates that the pointer will contain a null pointer value. If your array is global you don't even need to care. Then this will happen by default.
+1
source to share