The following code shows how to Create and Display Singly Linked List in C.
// Linked List Implementation
#include <stdio.h>
#include <stdlib.h>
struct node{
int data;
struct node* next;
};
struct node* head=NULL;
int main()
{
int d;
struct node *p, *q;
head=(struct node *)malloc(sizeof(struct node));
printf("Enter data for head node: ");
scanf("%d", &d);
head->data=d;
head->next=NULL;
q=head;
printf("Enter data for next node! To end, enter -99: ");
while(1)
{
scanf("%d", &d);
if(d==-99)
break;
p=(struct node *)malloc(sizeof(struct node));
p->data=d;
p->next=NULL;
q->next=p;
q=p;
}
p=head;
printf("\n\nNodes in the Linked List....\n");
while(p!=NULL)
{
printf("%d ", p->data);
p=p->next;
}
return 0;
}
Output
Further Reading
50+ C Programming Interview Questions and Answers
C Program to Find Factorial of a Number
- AI
- Android
- Angular
- ASP.NET
- Augmented Reality
- AWS
- Bioinformatics
- Biometrics
- Blockchain
- Bootstrap
- C
- C#
- C++
- Cloud Computing
- Competitions
- Courses
- CSS
- Cyber Security
- Data Science
- Data Structures and Algorithms
- Data Visualization
- Datafication
- Deep Learning
- DevOps
- Digital Forensic
- Digital Trust
- Digital Twins
- Django
- Docker
- Dot Net Framework
- Drones
- Elasticsearch
- ES6
- Extended Reality
- Flutter and Dart
- Full Stack Development
- Git
- Go
- HTML
- Image Processing
- IoT
- IT
- Java
- JavaScript
- Kotlin
- Latex
- Machine Learning
- MEAN Stack
- MERN Stack
- Microservices
- MongoDB
- NodeJS
- PHP
- Power Bi
- Projects
- Python
- Quantum Computing
- React
- Robotics
- Rust
- Scratch 3.0
- Shell Script
- Smart City
- Software
- Solidity
- SQL
- SQLite
- Tecgnology
- Tkinter
- TypeScript
- VB.NET
- Virtual Reality
- Web Designing
- WebAssembly
- XML