__frank__ wrote:
I'm referring to linked list.
In some codes I find:
/* 1 */
newNode=malloc(sizeof (struct* node));
in other ones, instead I find:
/* 2 */
newNode (list_type) malloc (sizeof (struct* node));
Which one is correct?
If you have included the proper header files, then both of the above
(once you fix the missing '=' for #2) are equivalent.
However...
You probably mean "sizeof(struct node)", and "sizeof(*newNode)" is even
better, as newNode's type can change and the malloc will automatically
get the right size.
And, if you don't remember to include the proper header file, then #2
will mask the error, so most people here will tell you the #1 is "better".
--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody |
www.hvcomputer.com | |
| kenbrody/at\spamcop.net |
www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>