Here is a snippet of code that is bugging me. The riddle is to allocate a node for a linked list in a function without returning the return statement.
So far I have this
#include <stdio.h>
#include <stdlib.h>
struct node
{
int value;
struct node *next;
} ;
void NewNode(struct node *newnode)
{
struct node *newnodeinstance;
newnodeinstance = malloc(sizeof(node));
newnodeinstance->value = 0;
newnodeinstance->next=NULL;
*newnode = newnodeinstance;
}
void main()
{
struct node *head;
int i=0;
NewNode(head);
head->value=100; // This causes unhandled exception. basically head is still NULL when I return from function.
}
What am I missing !!
-sl



LinkBack URL
About LinkBacks



