
C
huhuolianmeng
爱好电子,正在进军嵌入式,
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
C--递归汉诺塔解法
汉诺塔是由三根杆子A,B,C组成的。A杆上有n个(n>1)穿孔圆盘,盘的尺寸由下到上依次变小。要求按下列规则将所有圆盘移至C杆:每次只能移动一个圆盘;大盘不能叠在小盘上面。提示:可将圆盘临时置于B杆,也可将从A杆移出的圆盘重新移回A杆,但都必须尊循上述两条规则。问:如何移?最少要移动多少次?分析:(1)将A上n-1个盘子借助C移动到B;(2)将A剩下的一个盘子移动到C;(3)将B上n...转载 2019-12-29 22:53:23 · 158 阅读 · 0 评论 -
C--递归案例1
斐波拉存在如下数列1、1、2、4、7、13、24、44、81、149……,现要求该数列第n项的值(n从0开始算)。#include “stdio.h”int strlen_r(const char *s){if( *s ){return 1+strlen_r(s+1);}else{return 0;}}int fac(int n) //斐波拉{if( n >= ...原创 2019-12-29 22:34:44 · 160 阅读 · 0 评论 -
C--可变参数的使用
第一种方法实现求平均:#include <stdio.h>float average(int array[], int size){int i = 0;float avr = 0;for(i=0; i<size; i++){ avr += array[i];}return avr / size;}int main(){int array[] ...原创 2019-12-29 20:19:08 · 121 阅读 · 0 评论 -
C--函数参数的执行顺序
函数的参数的执行依赖于编译器,有可能从左到右,也有可能从右到左,程序中存在一定的顺序点。#include <stdio.h>int func(int i, int j){printf(“i = %d, j = %d\n”, i, j);return 0;}int f(){return 1;}int j(){return 7;}int main(){...原创 2019-12-29 20:15:50 · 377 阅读 · 0 评论 -
C--野指针1
#include <stdio.h>#include <malloc.h>int main(){int* p1 = (int*)malloc(40);int* p2 = (int*)1234567;int i = 0;for(i=0; i<40; i++){ *(p1 + i) = 40 - i;}free(p1); for(i=0;...原创 2019-12-29 16:13:59 · 133 阅读 · 0 评论 -
C--内存申请(清零)
#include <stdio.h>#include <malloc.h>#define SIZE 5int main(){int i = 0;int* pI = (int*)malloc(SIZE * sizeof(int));short* pS = (short*)calloc(SIZE, sizeof(short));for(i=0; i<SIZ...原创 2019-12-26 22:31:53 · 1624 阅读 · 0 评论 -
C--回调函数
// #include <stdio.h>// typedef int(*Weapon)(int);// void fight(Weapon wp, int arg)// {// int result = 0; // printf("Fight boss!\n"); // result = wp(arg); // ...原创 2019-12-26 20:02:49 · 136 阅读 · 0 评论 -
C-函数指针
// #include "stdio.h"// //函数重命名// typedef int (*f)(int,int); //定义一个指向函数类型的指针// typedef void (*f2)(int); // //定义函数指针// int add(int i,int j)// {// return i +j;// }// int main()// {// ...原创 2019-12-26 19:47:54 · 103 阅读 · 0 评论 -
C--动态申请二维数组
#include <stdio.h>#include <malloc.h>int** malloc2d(int row, int col){ int** ret = NULL; if( (row > 0) && (col > 0) ) { int* p = NULL; ...原创 2019-12-25 22:22:19 · 141 阅读 · 0 评论 -
C--程序开始就执行main函数嘛?
#include <stdio.h>#ifndef GNUC#define attribute(x)#endifattribute((constructor))void before_main(){printf("%s\n",FUNCTION);}attribute((destructor))void after_main(){printf("%s\n",FUN...原创 2019-12-25 22:01:34 · 236 阅读 · 0 评论 -
C--main函数的参数
#include <stdio.h>int main(int argc, char* argv[], char* env[]){ int i = 0; printf("============== Begin argv ==============\n"); for(i=0; i<argc; i++) { ...原创 2019-12-25 22:00:51 · 96 阅读 · 0 评论 -
C--二维数组
#include <stdio.h>#include <malloc.h>void printArray(int a[], int size){int i = 0;printf("printArray: %d\n", sizeof(a));for(i=0; i<size; i++){ printf("%d\n", a[i]);//二位数组在内存...原创 2019-12-25 22:00:14 · 115 阅读 · 0 评论 -
C--字符串
#include "stdio.h"#include "string.h"//字符串右移函数 笔试void right_shift_r(const char *src,char *buf,unsigned int n){ int i = 0; const unsigned int len = strlen(src); // printf("%d.\n",str...原创 2019-12-24 21:21:03 · 121 阅读 · 0 评论 -
C--数组参数
数组参数是在编译器编译的时候替换为指针:void f(int a[5]) <==>void f(int *a)#include <stdio.h>void func1(char a[5])//void f(int a[5]) <==>void f(int *a){ printf("In func1: sizeof(a) = %d\n", size...原创 2019-12-23 22:59:36 · 169 阅读 · 0 评论 -
C--指针(空间与平台有关)
#include <stdio.h>int main(){ int i = 0; int* pI; char* pC; float* pF; pI = &i; *pI = 10; printf("%p, %p, %d\n", pI, &i, i); printf("%d,...原创 2019-12-19 22:48:09 · 180 阅读 · 0 评论 -
C--宏定义
#include <stdio.h>#include <stdbool.h>#include <stdlib.h>#define Malloc(type,x) (type*)malloc(sizeof(type)*x)#define FREE§ (free§,p=NULL)#define LOG(s) printf("[%s] {%s:%d} %s"...原创 2019-12-18 22:53:33 · 167 阅读 · 0 评论 -
C--静态与动态链接库
1.C语言中的链接器(1)每个 C 语言源文件被编译后生成目标文件,这些目标文件最终要被链接在一起生成可执行文件。(2)链接器的主要作用是把各个模块之间相互引用的部分处理好,使得各个模块之间能够正确的衔接2.静态链接由链接器在链接时将库的内容直接加入到可执行程序中①编译静态库源码:gcc –c lib.c –o lib.o②生成静态库文件:ar –q lib.a lib.o //将 l...转载 2019-12-18 21:50:09 · 139 阅读 · 0 评论 -
C--逻辑运算等
#include <stdio.h>#include <stdbool.h>// char i = 1 ;int g = 0;int f1(void){ printf("the f1 is runed!.\n"); return g++;}int main(){ int aa = g || f1() && f1(); printf(...原创 2019-12-17 23:10:36 · 153 阅读 · 0 评论 -
C--typedef
#include <stdio.h>#include <stdbool.h>#include <stdlib.h>typedef int INT32;struct _tag_point{ int x; int y;};typedef struct _tag_point Point;typedef struct _tag_list...原创 2019-12-16 22:45:55 · 111 阅读 · 0 评论 -
C--enum枚举
#include <stdio.h>#include <stdbool.h>#include <stdlib.h>//define changliangenum { ARRARYSIZAE = 10};enum Color{ RED = 0x00FF0000, GREEN = 0x0000FF00, BL...原创 2019-12-16 21:45:53 · 118 阅读 · 0 评论 -
C--union联合体
*注意大小端小端模式:低地址存储低位数据大端模式:低地址存储高位数据#include <stdio.h>#include <stdbool.h>#include <stdlib.h>char System_Mode(){ union SM { int a; char b; }; un...原创 2019-12-16 21:22:17 · 132 阅读 · 0 评论