博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

随笔分类 -  C 语言

C 语言相关知识介绍与分享。
摘要:C++ 中 struct 与 class 的用法与区别 1. 概述 在 C++ 中,struct 与 class 都可以用来定义用户自定义类型(User-Defined Types)。 二者在语法能力上几乎完全相同,都可以: 定义成员变量 定义成员函数 构造函数 / 析构函数 访问修饰符(publi 阅读全文

posted @ 2025-11-20 22:06 steve.z 阅读(29) 评论(0) 推荐(0)

摘要:const pointer - const 指针 - 常量指针 - 指针本身是常量 - 指向不能变 把指针本身定义为常量,常量指针必须初始化。 一旦定义后,该常量指针中存放的地址就不能变了。 int a = 10; // const 关键字修饰指针 p int * const p = &a ; // 阅读全文

posted @ 2025-11-14 19:25 steve.z 阅读(6) 评论(0) 推荐(0)

摘要:代码解析: // 在 hello.h 文件中代码如下 #ifndef hello_h // 如果hello_h宏没有被定义 #define hello_h // 定义hello_h宏 // c code #endif // 结束条件编译 作用: 防止重复包含:当同一个头文件被多次#include时, 阅读全文

posted @ 2025-11-11 16:40 steve.z 阅读(13) 评论(0) 推荐(0)

摘要:一、词法分析器 // // main.c // LexiAnalize // // Created by steve xiaohu zhao on 2025/4/23. // #include <ctype.h> #include <stdio.h> #include <string.h> // 定 阅读全文

posted @ 2025-09-05 15:18 steve.z 阅读(127) 评论(0) 推荐(0)

摘要:// 根据模式串构建 next 数组 void buildNext(const char *pattern, int *next) { int i, j; int m = (int)strlen(pattern); next[0] = -1; for (j = 1; j < m; j++) { i 阅读全文

posted @ 2025-04-27 11:11 steve.z 阅读(47) 评论(0) 推荐(0)

摘要:要求: 任务描述 本关任务:使用C语言编写一个对C语言进行词法分析的程序。 编程要求 根据提示,在右侧编辑器补充代码,从标准输入流读取字符,并完成词法分析任务。 其中,单词可以分为以下几类 第1类:标识符,由字母开头,由字母和数字组成 第2类:保留字,共32个,已存储到keyword_list数组中 阅读全文

posted @ 2025-04-23 10:24 steve.z 阅读(225) 评论(0) 推荐(0)

摘要:// // main.c // 09_String // // Created by steve xiaohu zhao on 2025/4/20. // #include <stdio.h> #include <string.h> /// 暴力匹配算法(Brute Force)——方式一 /// 阅读全文

posted @ 2025-04-20 09:50 steve.z 阅读(63) 评论(0) 推荐(0)

摘要:伪代码: A: 数组名 n: 数组长度 BUBBLE-SORT(A, n) for i = 0 to n-2 for j = 0 to n-2-i if A[j] > A[j+1] swap A[j] with A[j+1] void bubbleSort(int A[], int n) { for 阅读全文

posted @ 2025-03-31 19:54 steve.z 阅读(7) 评论(0) 推荐(0)

摘要:伪代码: A: 数组名 n: 数组长度 SELECTION-SORT(A, n) for i = 0 to n-2 min_idx = i for j = i+1 to n-1 if A[j] < A[min_idx] min_idx = j if min_idx != i swap A[i] wi 阅读全文

posted @ 2025-03-31 19:45 steve.z 阅读(23) 评论(0) 推荐(0)

摘要:伪代码: A: 数组名。 n: 数组长度。 INSERTION-SORT(A, n) for i = 1 to n-1 key = A[i] j = i - 1 while j >= 0 and A[j] > key A[j + 1] = A[j] j = j - 1 A[j + 1] = key 阅读全文

posted @ 2025-03-31 19:35 steve.z 阅读(31) 评论(0) 推荐(0)

摘要:// // main.c // 01递归理解:通过求阶乘(factorial)和斐波那契数列(fibonacci sequence)理解递归 // // Created by steve xiaohu zhao on 2025/2/7. // #include <stdio.h> // 1. 求阶乘 阅读全文

posted @ 2025-02-07 11:10 steve.z 阅读(53) 评论(0) 推荐(0)

摘要:// // main.c // Test_C // // Created by steve xiaohu zhao on 2025/1/20. // #include <stdio.h> // C 语言指针传递参数(引用传递) void swap(int *px, int *py) { int t 阅读全文

posted @ 2025-01-20 15:28 steve.z 阅读(64) 评论(0) 推荐(0)

摘要:// // Created by steve xiaohu zhao on 2025/1/20. // /** * * 线性表的顺序存储结构实现 * 特点:逻辑上相邻的元素,物理上也相邻 * */ #include <stdio.h> #include <stdlib.h> #define MAXS 阅读全文

posted @ 2025-01-20 14:58 steve.z 阅读(65) 评论(0) 推荐(0)

摘要:// // main.c // HuffmanTree // // Created by steve xiaohu zhao on 2023/10/18. // #include <stdio.h> #include <stdlib.h> // 定义一个 Huffman Tree 的节点 struc 阅读全文

posted @ 2023-10-18 14:44 steve.z 阅读(23) 评论(0) 推荐(0)

摘要:// // main.c // BinarySearch // // Created by steve xiaohu zhao on 2023/10/16. // #include <stdio.h> // 二分法查找指定元素在数组中出现的索引位置 int BinarySearch(int *arr 阅读全文

posted @ 2023-10-17 16:17 steve.z 阅读(81) 评论(0) 推荐(0)

摘要:typedef int Position; typedef struct LNode *List; struct LNode { ElementType Data[MAXSIZE]; Position Last; }; /* 初始化 */ List MakeEmpty() { List L; L = 阅读全文

posted @ 2023-10-16 20:54 steve.z 阅读(17) 评论(0) 推荐(0)

摘要:// // main.c // SeqList2 // // Created by steve xiaohu zhao on 2023/10/15. // #include <stdio.h> #include <stdlib.h> #define MAXSIZE 100 /* 表示线性表的最大长度 阅读全文

posted @ 2023-10-16 20:13 steve.z 阅读(30) 评论(0) 推荐(0)

摘要:// // main.c // SeqList // // Created by steve xiaohu zhao on 2023/10/15. // #include <stdio.h> #include <stdlib.h> #define MAXSIZE 100 // 定义一个顺序表的节点 阅读全文

posted @ 2023-10-15 21:34 steve.z 阅读(42) 评论(0) 推荐(0)

摘要:```c #include // 循环 void printN(int n) { int mod = 0; while ((mod = n % 10) != 0) { printf("%d\n", mod); n = n / 10; } } // 递归 void printn(int n) { pr 阅读全文

posted @ 2023-08-03 12:12 steve.z 阅读(32) 评论(0) 推荐(0)

摘要:```c #include #include // 1. 定义一个结构体(先定义结构体再声明变量) struct Student { int no; char *name; char sex; float score; }; // 2. 在定义结构体类型的同时声明结构体变量 struct Teach 阅读全文

posted @ 2023-08-02 11:13 steve.z 阅读(46) 评论(0) 推荐(0)