Saturday, February 10, 2018

C Syntax Explanation



Hey guys I'm Studying C Language I need some explanation about a code segments,



int *p;
p = (int *) malloc(sizeof(int));


What does the (int *) means and whats really happening when you execute the above Code, Thaks In Advance.



Answer



(int *) is a so called cast operator. It is used to convert the value on the right side of the operator to the type enclosed in parenthesis.



Here, it is used to convert the void * pointer returned by malloc() to an int *, i.e. a pointer to an integer.



This is a very bad usage, and you should not do it.


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...