First create a structure
struct LIST { int field; struct LIST *pNext; }; struct LIST* pHead; инициализирую первый элемент struct LIST* init(int number) { struct LIST *lst; lst = (struct LIST*)malloc(sizeof(struct LIST)); lst->field = number; lst->pNext = NULL; return lst; }; struct LIST* add(struct LIST* lst, int number) { struct LIST * pNew; pNew = (struct LIST*)malloc(sizeof(struct LIST)); pNew->field = number; pNew->pNext = lst->pNext; //2 lst->pNext = pNew; //3 return pNew; } int main() { pHead = init(5); struct LIST* pTmp = add(pHead, 10); } Question: how does the add function work, it is especially incomprehensible what is being done here, what happens with pointers and how to understand this lst-> pNext Why does the call have to happen via pNew and how does it differ from the call with lst?
pNew->pNext = lst->pNext; //2 lst->pNext = pNew; //3 And can you please explain what the program does in general?