# Count Number of Nodes in a Linked List

Write a c program to count number of nodes in a linked list. In this tutorial, We are going to write a c code to count the number of nodes in a linked list.

A linked list is a collection of nodes, each pointing to next node by means of a pointer. In linked list, each node consists of two parts, a data and a pointer to next node.

C Program to Count Number of Nodes in a Linked List

## An Algorithm to Count Number of Nodes in a Linked List

i) Take a count variable and initialize it to zero, count = 0.

Subscribe Our Tutorials

ii) Traverse a linked list and increment a count variable.

iii) When a node points to a null, it means we reach at end of a linked list then return the value of a count variable.

Objective Questions for Practice

## C Program to Count Number of Nodes in a Linked List

The time complexity to count the number of nodes in a linked list is O(n).

C Program to Insert Node at the head of a Linked List

C Program to Delete a Linked List

C Program to Reverse a Linked List