07 2023 档案

摘要:函数指针使用案例(回调函数) 代码: #include <stdio.h> void A(){ printf("Hello"); } void B(void (*ptr)())//B函数有一个函数指针作为它的参数 { //ptr指向一个函数,这个函数应该是不带参数的而且返回void,就像A那样 pt 阅读全文
posted @ 2023-07-30 10:46 Ninnne 阅读(16) 评论(0) 推荐(0)
摘要:函数返回指针 ## 一: 代码: #include <stdio.h> #include <stdlib.h> int Add(int a,int b){ int c = a + b; return c; } int main(){ int x = 2, y = 4; int z = Add(x,y 阅读全文
posted @ 2023-07-29 15:41 Ninnne 阅读(20) 评论(0) 推荐(0)
摘要:指针练习 声明变量:pstr是一个指向数组的指针,该数组内含20个char类型的值 char (*pstr)[20]; 编写一个函数,返回储存在int类型中数组中的最大值,并在一个简单的程序中测试该函数 #include <stdio.h> int get_max(int number[],int 阅读全文
posted @ 2023-07-28 15:48 Ninnne 阅读(29) 评论(0) 推荐(0)
摘要:堆上分配内存的相关函数 进行动态内存分配时常用的库函数 一:malloc函数 函数定义:void* malloc(size_t size) 参数是在heap里分配的内存空间的字节数大小,数据类型是size_t(正整数) 例:表示在堆上请求四个字节,我们把malloc返回的地址存入void指针变量 v 阅读全文
posted @ 2023-07-27 21:55 Ninnne 阅读(18) 评论(0) 推荐(0)
摘要:指针4 练习 一: 代码: #include <stdio.h> ​ int main(){ int (*ptr)[2]; int a[2][2]={12,14,16}; ptr=a; printf("%d\n",**ptr); printf("%d",**(ptr+1)); } 输出结果: 12 阅读全文
posted @ 2023-07-27 20:20 Ninnne 阅读(9) 评论(0) 推荐(0)
摘要:指针3 指针和多维数组 代码: #include <stdio.h> int main(){ int C[3][2][2]={{{2,5},{7,9}}, {{3,4},{6,1}}, {{0,8},{11,13}}}; printf("%d %d %d %d\n",C,*C,C[0],&C[0][ 阅读全文
posted @ 2023-07-26 21:51 Ninnne 阅读(15) 评论(0) 推荐(0)
摘要:# 指针2 ## 一:指针和字符数组 字符数组和字符串看末尾是否有\0 。“hello ”是字符数组,“hello\0”是字符串 1. 代码: ```c #include #include //要用字符串函数就必须带上 int main(){ char C[20]; C[0] = 'J'; C[1] 阅读全文
posted @ 2023-07-25 21:24 Ninnne 阅读(14) 评论(0) 推荐(0)
摘要:# 指针 ## 一:指针代码示例 [B站视频]([指针和数组_哔哩哔哩_bilibili](https://www.bilibili.com/video/BV1bo4y1Z7xf?p=6&vd_source=3a1039a0cf604eeb256aff7809e75f6e)) 代码 ```c #in 阅读全文
posted @ 2023-07-25 15:14 Ninnne 阅读(16) 评论(0) 推荐(0)