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编写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){…
c语言中声明常量的两种方式 const int value int const value 如果要声明常量的指针,即指向常量的指针,则可以参考上面的常量声明修改一下 const int *ptr int const *ptr 把*ptr看成一个整体,那么*ptr中的ptr就是指向常量的指针了.顾名思义,指向常量的指针,那么就不可以通过这个指针去修改这个值了. #include <stdio.h> int main(){ int val = 123; int const *ptr = &…
代码块作用域: 任何位于一对花括号之间是一个代码块,代码块内声明的标识符具有代码块作用域,嵌套代码块内,内部变量会屏蔽外部相同标示的标示符,非嵌套代码块,不会同时处于活动状态所以不会屏蔽. int main() { int value = 123; { int value = 456; printf("%d\n", value); } { int value = 789; printf("%d\n", value); } printf("%d\n"…
[C++Primer]第五版[学习笔记]习题解答第三章 ps:答案是个人在学习过程中书写,可能存在错漏之处,仅作参考. 作者:cosefy Date: 2020/1/10 第三章:字符串,向量和数组 练习3.2: #include<iostream> #include<string> using std::string; using std::cout; using std::cin; using std::endl; int main() { string line; //whi…