首先我定义了这个结构:
typedef struct{
int **_data;
int _num_of_lines;
int *_lines_len;
} Lines;
我的目标是接收_num_of_lines
用户的输入。它将用于定义二维数组的行数,data
而数组_lines_len
表示每行的长度data
我正在尝试 malloc 内存_lines_len
,但我总是返回数组的大小为 2,我不明白为什么......
int main(int argc, char *argv[]) {
Lines linesStruct;
printf("enter num of lines:\n ");
scanf("%d",&linesStruct._num_of_lines);
printf("Num of lines is = %d \n", linesStruct._num_of_lines);
linesStruct._lines_len = (int*) malloc(linesStruct._num_of_lines * sizeof(int));
int len = (int) ((sizeof(linesStruct._lines_len))/(sizeof(int)));
printf("number of lines len = %d \n", len);