Segmentation fault somewhere


can you please tell me why this code isnt working

Hi… u are not building the linked list only correctly… refer this https://ide.codingblocks.com/s/608567

but i still dont get what was wrong with my code…why was i getting a segmentation fault??

can you please elaborate the step where i was wrong

https://ide.codingblocks.com/s/608675 i have corrected ur code…
and i highly suggest u to go and watch video lectures on building linked list as it is not possible to explain the same here…

I did check the videos- my logic was same just a slight difference in implementation which I think you are suggesting. I got the building logic - you are adding the nodes from the end I was adding them from head. but it still doesn’t explain exactly which expression was causing the segmentation fault :frowning:

firstly according to ques we have to insert nodes at end and not in front…
secondly in main function when u declared head initialize it with NULL.
and whenever u create a first node u have to handle the base case as i have shown my code… rest if u still are not getting it i suggest u to dry run it using pen and paper u would get a better insight

thanks, i got it now, silly mistakes on my end

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.