I found this line of code in some code I'm analyzing:
Mintau = (double*) malloc(FadeAll.num_paths*sizeof(double));
I also found a question on here (that was a duplicate of other questions it appears) that explains different syntax of pointers including:
int *ptr;
int * ptr;
int* ptr;
I should explain that I fully understand that all three of the above are saying the same thing. The last one is the one that most closely resembles my line of code. What I was wondering is why double has to be in parenthesis in this case? I apologize if this is a duplicate question but I couldn't find any regarding this.
There are no difference between this three declarations:
int *ptr;
int * ptr;
int* ptr;
(double*) has to be in parenthesis because it is a Cast.
Read a little about casting in this link
Hope it helps.
That signifies a cast. The function malloc returns a void*. The (double*) casts that value to be of type double*.
In C, this cast is needless since any pointer type is assignment compatible with void*. But if this was C++ then the cast would be needed.
There is no difference between:
int *ptr;
int * ptr;
int* ptr;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With