Created: 2022-06-26
Tags: #permanent
Node, a component of a data structure that encapsulates some information.
typedef struct node {
int val;
struct node *next;
}
node;
Explanation of the code above
typedef struct node so that we can refer to a struct node inside our struct.int called val, for the value we want to store, and then a pointer to the next node with struct node. (We haven’t fully defined node yet, so the compiler needs to know it’s a custom struct still.node at the end let us use just node in the rest of our program.node *n = malloc(sizeof(node));
if (n == NULL)
{
// I'm just going to clean up and quit
free(n);
return 1;
}