所以我想打印一个数组,数组的大小取决于此函数"m=(Movie*) malloc(ANY NUMBER * sizeof(Movie));"
中引入的值,但是我总是得到8作为“ m”的值,我在第一行的开头写了几行循环尝试调试它,但我找不到解决方案,如果您能找到任何帮助,它将非常棒。谢谢
#include <stdio.h>
#include <stdlib.h>
typedef struct movie{
int length;
} Movie;
int main(){
Movie *m=NULL;
m=(Movie*) malloc(3 * sizeof(Movie));
for (int i = 0; i < (sizeof(m)/sizeof(Movie)); i++)
{
printf("%d and %d\n",(int)sizeof(m), (int)sizeof(Movie));
printf("Enter the array number %d\n",i);
scanf("%d",&m[i].length);
}
for (int i = 0; i < (sizeof(m)/sizeof(Movie)); i++)
{
printf("Displayed: %d\n",m[i].length);
}
free(m);
return 0;
}