c语言学习笔记
主要是学习c语言时的一些笔记
南林夕
这个作者很懒,什么都没留下…
展开
-
5、释放指针
利用二级指针释放一级指针 正确案例 #include <stdio.h> #include <stdlib.h> #include <string.h> void P_Free(char **myp) { if(myp == NULL) { return ; } free(*myp); *myp = NULL; } int main() { char *p = NULL; p = (char *)malloc(10原创 2021-03-13 09:08:15 · 400 阅读 · 0 评论 -
4、递归字符串的反转
1、通过递归的方式逆序打印 2、递归和全局变量(把逆序的结果存入全局变量) 3、递归和非全局变量(递归指针做函数参数) 全局变量 #include <stdio.h> #include <string.h> char g_buf[20]; void inverse(char *p) { if(p == NULL) { return ; } if(*p == '\0') { return ; } inverse原创 2021-03-12 20:36:53 · 162 阅读 · 0 评论 -
3、栈的属性
栈的方向 #include <stdio.h> int a; int b; char buf[128]; //静态联邦的时候buff所代表的内存空间的标号,就已经定义下来了 printf("&a:%d &b:%d",&a,&b); 1、一般情况下,栈的开口方向是向下的。 目的:避免了栈的溢出。 2、不管栈开口的方向向下还是向上buff的方向永远是是向上的。 3、栈的生长方向和buf的内存增长方向是两个不同的概念 函数调用模型 1、main函数中可以在栈原创 2021-03-06 12:41:41 · 219 阅读 · 0 评论 -
2、变量的本质,内存四区
变量的本质 内存的别名。 #include<stdio.h> #include<stdlib.h> #include<string.h> int main() { int a; a = 10; printf("&a :%d\n",&a);//6422044 *((int *)6422044) = 100; printf("a :%d\n",a);//6422044 } 运行结果结果 内存四区 栈区:程序局部变量区。 堆区:Ma原创 2021-03-04 21:17:12 · 105 阅读 · 1 评论 -
1、数据类型提高
数据的本质:固定大小内存块的别名 #include<stdio.h> #include<stdlib.h> #include<string.h> int main() { int a;//告诉编码器分配4各字节的内存 int b[10];//告诉c编译器分配40内存字节 printf("b:%d, b+1:%d, &b:%d, &b+1:%d\n",b,b+1,&b,&b+1); //b+1 &原创 2021-03-03 21:56:08 · 62 阅读 · 2 评论 -
一级字符串容易出错笔记及const修饰符学习
1 #include<stdio.h> #include<stdlib.h> #include <string.h> #include <ctype.h> int main() { char buff[1024] = {0}; //不是buff[0] = 0;而是定义为buff[0] - buff[1024] ='\0'; printf("%c\n",buff[0]); char *p = {0}; //不是*p = ‘0’; //而是等于原创 2020-11-07 17:04:46 · 125 阅读 · 0 评论 -
定义一个接口,实现根据key获取valude练习
#include<stdio.h> #include<stdlib.h> #include <string.h> #include <ctype.h> /*键值对""key = valude”)字符串,在开发中经常使用; 要求1:请自己定义一个接口,实现根据key获取yalude;40分 要求2:编写测试用例。30分s 要求3:键值对中间可能有n多空格,请去除空格30分 注意:键值对字符串格式可能如下 "key1 = valued1" "key2 =原创 2020-11-07 16:40:06 · 309 阅读 · 0 评论