int (*p)[2];
p=(int(*))malloc(sizeof(int[2])*100);
What is the right way to malloc a pointer to an array?
I can’t figure out the part with (int(*))
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Posting comments as answer:
In
Cyou should not to cast the return value ofmalloc. Please refer this post on SO for more information regarding why typecasting return value ofmallocis not a good idea inC. And if for some reason you really really want to cast, it should be(int(*)[2]).(int(*))isint *. The size passed to malloc looks fine (allocating size for 100 pointers to array of 2 ints). So you should be doingHope this helps!