Iterating through a linked list

To iterate through a linked list in C, you can use a while loop to traverse the list from the beginning to the end. Here's an example of how you can achieve this:

struct Node {
    int data;
    struct Node* next;
};

void traverseLinkedList(struct Node* head) {
    struct Node* current = head; // Start from the head of the linked list
    while (current != NULL) { // Continue until the end of the list is reached
        // Process the current node, for example, print its data
        printf("%d ", current->data);
        current = current->next; // Move to the next node
    }
}

In this example, we define a structure for the nodes of the linked list, and then we create a function traverseLinkedList that takes the head of the list as a parameter. Inside the function, we use a while loop to iterate through the list, processing each node as we go.