(It is in the c program.In linked list.)
struct node
{
int data;
struct node *link;
};
/*when we allocate the memorary for the new node */
void append(struct node **q,int data)
{
struct *temp;
temp = malloc(sizeof(struct node); /* 1 */
/* AND */
temp = (struct node *) malloc( sizeof (struct node) ); /* 2 */
}
/* tell the difference between different code for allocation
in line 1 we dont mention the cast type
%26amp;
in line second we mention the cast type.
*/
What is the difference between the line mention below:-?
For all intents and purposes there is no difference between the two. Since malloc returns a void *, casting (example 2) is purely optional. The only real difference only comes into play if you forget to include stdlib (example 1 will generate an error because the compiler defaults to functions returning int's if a formal declaration is not found, example 2 might slip through the cracks since you're doing an explicit cast).
Reply:Both works fine. But, the second is considered as 'Good programming practice'.
Reply:Hi :
plz may you explain more , or put another question
thanx
have a nice day
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment