引言C语言作为一门历史悠久且广泛使用的编程语言,在系统软件、嵌入式系统、操作系统等领域有着广泛的应用。本文将带领读者从C语言的入门知识开始,逐步深入到实战技巧和案例分析,帮助读者全面掌握C语言编程。第...
C语言作为一门历史悠久且广泛使用的编程语言,在系统软件、嵌入式系统、操作系统等领域有着广泛的应用。本文将带领读者从C语言的入门知识开始,逐步深入到实战技巧和案例分析,帮助读者全面掌握C语言编程。
C语言由Dennis Ritchie在1972年发明,最初是为了在贝尔实验室的PDP-11上编写操作系统Unix。自那时起,C语言经历了多次改进,逐渐成为一门功能强大、应用广泛的编程语言。
#include
void bubbleSort(int arr[], int n) { int i, j, temp; for (i = 0; i < n - 1; i++) { for (j = 0; j < n - i - 1; j++) { if (arr[j] > arr[j + 1]) { temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; } } }
}
int main() { int arr[] = {64, 34, 25, 12, 22, 11, 90}; int n = sizeof(arr) / sizeof(arr[0]); bubbleSort(arr, n); printf("Sorted array: \n"); for (int i = 0; i < n; i++) { printf("%d ", arr[i]); } printf("\n"); return 0;
} #include
#include
// 定义链表节点结构体
struct Node { int data; struct Node* next;
};
// 创建新节点
struct Node* createNode(int data) { struct Node* newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->data = data; newNode->next = NULL; return newNode;
}
// 向链表尾部添加节点
void appendNode(struct Node** head, int data) { struct Node* newNode = createNode(data); if (*head == NULL) { *head = newNode; return; } struct Node* temp = *head; while (temp->next != NULL) { temp = temp->next; } temp->next = newNode;
}
// 打印链表
void printList(struct Node* head) { struct Node* temp = head; while (temp != NULL) { printf("%d ", temp->data); temp = temp->next; } printf("\n");
}
int main() { struct Node* head = NULL; appendNode(&head, 1); appendNode(&head, 2); appendNode(&head, 3); appendNode(&head, 4); appendNode(&head, 5); printf("Linked List: \n"); printList(head); return 0;
} 通过本文的学习,读者应该对C语言有了全面的认识。从入门到实战,本文详细介绍了C语言的基础知识、进阶技巧和案例分析。希望读者能够通过本文的学习,掌握C语言编程,并在实际项目中发挥其作用。