c++ – appending a node to a linked list and then display the linked list


Hello everyone I am trying to append a node to a linked list and the display it. However, Xcode Analyze reports a couple of problems:
1. value stored to ‘head’ is never read
2. Potential leak of memory pointed to by ‘head’

#include <iostream>
using namespace std;

struct LinkedList

{
    int value;      // the value in this node
    struct LinkedList *next; // to point to the next node

};

void appendNode (int, LinkedList *);
void insertNode ();
void deleteNode ();
void displayList(LinkedList *) ;


int main()
{

    LinkedList *head;

    head = nullptr;
    int num;
    int numOfNodes;

    cout << "Enter the number of initial nodes: ";
    cin >> numOfNodes;

    for(int i = 0; i < numOfNodes; i++)
        {
            cout << "Enter a number: ";
            cin >> num;
            appendNode(num, head);
        }
    displayList(head);


    cout << "end of entering" << endl;
}
// function definition for appendnode

void  appendNode(int num, LinkedList *head)
{
    LinkedList *newNode;
    LinkedList *nodePtr;



    // allocate a new node and store num there
    newNode = new LinkedList;
    newNode->value = num;
    newNode->next = nullptr;


    // if there are no nodes in the list
    // make new node the first node
    if(!head)
    {
    // if !head(head is null or 0)
        head = newNode; // error 1. value stored to 'head' is never read

    }

    else // Otherwise, insert newNode at end
    {
        // initialize nodeptr to head of list
        nodePtr = head;


            // find the last node in the list
        while(nodePtr->next)
               nodePtr = nodePtr->next;// keep moving node ptr up until the last node

        nodePtr->next = newNode;



    }


} // error 2. Potential leak of memory pointed to by 'head'

void displayList(LinkedList *head)
{
    LinkedList *nodePtr;



    nodePtr = head;


    while(nodePtr != nullptr)
    {

        //display the value in this node
        cout << nodePtr->value << endl;

        // move node to the next node
       nodePtr = nodePtr->next;
    }

}