int (*p)[2]; p=(int(*))malloc(sizeof(int[2])*100);
What is the correct way for a malloc pointer to an array? I can not determine the part with (int (*))
Sending comments as an answer:In Cyou do not specify a return value malloc. Please refer to this SO format post for more information on why return value of return value is mallocnot a good idea in C. And if for some reason you really want to quit, it should be (int(*)[2]). (int(*)) int *. The size passed to malloc looks good (allocating size for 100 pointers for an array of 2 integers). Therefore you must do
C
malloc
(int(*)[2])
(int(*))
int *
int (*p)[2]; p=malloc(sizeof(int[2])*100);
, !
, . , , 100 int , int ( ints), malloc 100 100 int, .
"malloc ". malloc , malloc . , , .