I have implemented a LinkedList with the ability to add, get elements from a particular position and ability to show all the elements in the array in to the console (main purpose to implement this was to ensure that all the elements are being populated in the LinkedList correctly).I would highly appreciate comments based on:The efficiency of my codeConceptual misinterpretations of a linked list, if anyViolations of best practicesBetter way of achieving thisThis is the code I have written:#include <stdio.h>#include <stdlib.h>struct Element {    int value;    struct Element *nextElement;};struct LinkedList {    struct Element *firstElement;   };void add(struct LinkedList *list, int value) {    if(list->firstElement == NULL) {        struct Element *newElement;        newElement = malloc(sizeof(struct Element));        newElement->value = value;        newElement->nextElement = NULL;        list->firstElement = newElement;    } else {        struct Element *lastElement;        lastElement = list->firstElement;        while(lastElement->nextElement != NULL) {            lastElement = lastElement->nextElement;           }        struct Element *newElement;        newElement = malloc(sizeof(struct Element));        newElement->value = value;        newElement->nextElement = NULL;        lastElement->nextElement = newElement;    }}int getElement(struct LinkedList *list, int index) {    int iteratedIndex = 0;    int returnValue = 0;    struct Element *temporaryElement = list->firstElement;    while(temporaryElement != NULL) {        if(iteratedIndex == index) {            returnValue = temporaryElement->value;            return returnValue;        }        iteratedIndex = iteratedIndex + 1;        temporaryElement = temporaryElement->nextElement;    }    return 0;}void showAllElements(struct LinkedList *list) {    struct Element *lastElement = list->firstElement;    while(lastElement != NULL) {        printf(%d\n, lastElement->value);        lastElement = lastElement->nextElement;    }}int main(){    struct LinkedList list = {NULL};    add(&list, 5);    add(&list, 10);    add(&list, 15);    showAllElements(&list);    int value = getElement(&list, 0);    printf(%d\n, value);    return 0;   }Here's the output I got:510155Which is correct, first three listing all the elements in the LinkedList and last one fetching the element in the 0th index.
Simple singly linked list implementation in C
c;linked list;c99
Well, you have consistent indentation and your code compiles and runs cleanly as C99+ (not C90), that's a good start.So, the data-types:Consider adding typedef-names equal to the struct tags. Makes it more pleasant to work with.LinkedList is just an Element*, so making it a typedef instead of its own struct-type should be preferred.Putting nextElement first is probably slightly more efficient. And it's certainly more common.Your names are curious. Call it Node and List, to be consistent with common usage, and the elements of a Node would be next and value (or data).Consider giving your list-functions a common prefix (C's alternative to C++ namespaces).typedef struct Node {    struct Node* next;    int value;} Node;typedef node* List;Let's move on to add, which is far too complicated.A single Node** simplifies things enormously.I also used a compound-literal for more comfortable initializationAnd you have to do something if allocation fails.Don't use sizeof with a type, use it with the appropriate expression. That's more resilient to change and less error-prone.void add(List* head, int value) {    while(*head)        head = &head[0]->next;    *head = malloc(sizeof **head);    if(!*head) abort();    **head = (Node){0, value};}Going to getElement:What's returnValue for, aside from additional typing?The other temporary can also be usefully eliminated.Not sure returning 0 for too-high indices is that good an idea, but one can do it.It's returning the value of an element, not the element itself.int getValue(List* head, int index) {    Node* node = *head;    while(index && node)        node = node->next, --index;    return node ? node->value : 0;}showAllElements is the perfect place for a for-loop, so let's use that:void showAllElements(List* head) {    for(Node* p = *head; p; p = p->next)        printf(%d\n, p->value);}return 0; is implicit in C99+ for main.As a general point, either avoid adding things unto the end of your list instead of the front, take advantage of easy linear-time constant-space list-reversal, or manage an additional pointer to the last node.See it working on coliru.