#include <stdio.h>
#include <stdlib.h>
struct node
{
int val;
node * p_next;
};
int main(void)
{
node *test;
allocates the right amount of bytes to the node pointer.
test = malloc( sizeof(node) );
test->val = 123;
test->p_next = NULL;
printf("%d %p %p\n",test->val,test,test->p_next );
free(test);
printf("Press enter to continue.... \n");
getchar();
return 0;
}
Then i get this error and i do not understand why i should get even though i gave the type for the node pointer.
error: invalid conversion from 'void*' to 'node*' [-fpermissive]
test = malloc( sizeof(node) );
^