Why segmentation fault is showing in my code?

the problem is you are passing head as pass by value in insert() function, so head will be always null, no matter how many elements you added.

updated code: https://ide.codingblocks.com/s/211654

thanks