C和指针 第十一章 习题】的更多相关文章

1编写calloc,内部使用malloc函数获取内存 #include <stdio.h> #include <stdlib.h> void *myAlloc(unsigned long int length, unsigned long int typeSize) { int *ptr; int index = 0; int totalLen = length * typeSize; if(length >= 0 && typeSize >= 0){…
6.1编写一个函数,它在一个字符串中进行搜索,查找所有在一个给定字符集中出现的字符,返回第一个找到的字符位置指针,未找到返回NULL #include <stdio.h> char * find_char(char const *source, char const *chars) { char const *sptr = source; char const *cptr = chars; if (sptr == NULL || cptr == NULL) { return NULL; } w…
17.8 为数组形式的树编写模块,用于从树中删除一个值,如果没有找到,程序节点 ArrayBinaryTree.c // // Created by mao on 16-9-18. // #include "ArrayBinaryTree.h" #include <assert.h> #include <stdio.h> unsigned long leftChild(unsigned long current) { return 2 * current; }…
1,1标准输入读入字符,统计各类字符所占百分比 #include <stdio.h> #include <ctype.h> //不可打印字符 int isunprint(int ch){ return !isprint(ch); } //转换表,储存各个判断函数指针 int (*tables[])(int) = {iscntrl, isspace, isdigit, islower, isupper, ispunct, isunprint}; int main() { int co…
声明数组时,必须指定数组长度,才可以编译,但是如果需要在运行时,指定数组的长度的话,那么就需要动态的分配内存. C函数库stdlib.h提供了两个函数,malloc和free,分别用于执行动态内存分配和释放,这些函数维护一个可用的内存池,当程序需要内存时,它就调用malloc从内存池中提取一块合适的内存,并向该程序返回一个指向这块内存的指针,这块内存没有以任何方式进行初始化.如果需要初始化,可用使用calloc函数.当一块分配的内存不再使用时,程序应该调用free函数把它归还给内存池. void…
7.1 hermite递归函数 int hermite(int n, int x) { if (n <= 0) { return 1; } if (n == 1) { return 2 * x; } return 2 * x * hermite(n - 1, x) - 2 * (n - 1) * hermite(n - 2, x); } 7.2两个整型值M和N(m.n均大于0)的最大公约数计算公式: gcd(M,N) 当M % N = 0;  N 当M % N =R, R > 0; gcd(N…
第一题 package net.mindview.holding.test1; import java.util.ArrayList; import java.util.List; /** * 沙鼠 * @author samsung * */ public class Gerbil { static int counter; int gerbilNumber; public Gerbil(){ this.gerbilNumber = counter ++; } public String ho…
下列输出的值: #include <stdio.h> int func(){ static int count = 1; return ++count; } int main() { int answer = 0; answer = func() - func() * func(); printf("%d\n", answer); return 0; } answer = 2 - 3 * 4; 所以结果 -10: 5.3 编写函数 unsigned int reverse_…
4.1正数的n的平方根可以通过: ai+1= (ai + n / ai ) / 2 得到,第一个a1是1,结果会越来越精确. #include <stdio.h> int main() { double input; double exp; scanf_s("%lf", &input); double aBefore = 1; double aNow = (aBefore + input / aBefore) / 2; exp = aBefore - aNow; e…
在一个源文件中,有两个函数x和y,定义一个链接属性external储存类型static的变量a,且y可以访问,x不可以访问,该如何定义呢? #include <stdio.h> void x() { } int a = 1;//变量的作用域是在定义的地方开始所以放在y前面即可,默认链接属性external,储存类型static void y() { }…