代码改变世界

随笔档案-2022年11月

函数指针

2022-11-17 21:13 by 钟铧若岩, 16 阅读, 收藏, 编辑
摘要: 1 #include <cstdio> 2 #include <iostream> 3 using namespace std; 4 int max(int x,int y) 5 { 6 return x>y?x:y; 7 } 8 int main() 9 { 10 int max(int,int) 阅读全文

重载为什么一定要指针才行呢?请专家解答下

2022-11-17 20:59 by 钟铧若岩, 26 阅读, 收藏, 编辑
摘要: 请教专家,为什么下面的代码都是输出 A类的方法,而采用指针才能达到重载的目的。 1 #include <endian.h> 2 #include <iostream> 3 using namespace std; 4 5 class A 6 { 7 public: virtual void prin 阅读全文

通过传地址,传引用交换两个数的值

2022-11-17 20:21 by 钟铧若岩, 29 阅读, 收藏, 编辑
摘要: 1 #include <cstdio> 2 #include <iostream> 3 using namespace std; 4 5 void swapxy(char *a ,char *b) 6 { 7 int c = *a; 8 *a = *b; 9 *b = c; 10 } 11 void 阅读全文

指针的指针,以及指针传递

2022-11-15 22:40 by 钟铧若岩, 37 阅读, 收藏, 编辑
摘要: 1 #include <cstddef> 2 #include <cstdlib> 3 #include <iostream> 4 #include "string.h" 5 using namespace std; 6 7 8 void GetMemory(char **p,int num) 9 阅读全文

指针运算

2022-11-15 22:27 by 钟铧若岩, 19 阅读, 收藏, 编辑
摘要: 1 #include <iostream> 2 using namespace std; 3 int main() 4 { 5 int a =100; 6 int *b = &a; 7 char *c; 8 char *d = "hello world"; 9 c = d; 10 cout << " 阅读全文

批针与引用的区别

2022-11-15 21:42 by 钟铧若岩, 28 阅读, 收藏, 编辑
摘要: 1)非空区别 在任何情况下都不能使用指向空值的引用,一个引用必须总是指向某些对象 2)合法性区别 在使用引用之前不需要测试它的合法性,相反,指针则应总被测试,防止其为空。 3)可修改区别 指针可以被重新赋值以指向另一个不同的对象,但是引用则总是指向在初始化时被指定的对象 4)应用区别 指针可指向空, 阅读全文

空类与多重继承占用空间大小

2022-11-15 21:31 by 钟铧若岩, 14 阅读, 收藏, 编辑
摘要: 虚继承涉及虚表(虚指针),所以sizeof(C) = 8 1 #include <iostream> 2 using namespace std; 3 4 class A{}; 5 class A2{}; 6 class B:public A 7 {}; 8 9 class C:public vir 阅读全文

Class,strict sizeof用法

2022-11-13 15:26 by 钟铧若岩, 20 阅读, 收藏, 编辑
摘要: 1 #include "iostream" 2 using namespace std; 3 4 class A{}; 5 class A2{char d,e;}; 6 struct B{}; 7 struct C{char b,c;}; 8 struct D{int x,y;}; 9 10 int 阅读全文

Size of的用法

2022-11-13 15:10 by 钟铧若岩, 78 阅读, 收藏, 编辑
摘要: 1 #include <cstdlib> 2 #include <iostream> 3 #include <iterator> 4 #include "string.h" 5 using namespace std; 6 struct{ 7 short a1; 8 short a2; 9 shor 阅读全文

const的作用

2022-11-13 12:04 by 钟铧若岩, 77 阅读, 收藏, 编辑
摘要: 1)定义const常量 2)const可以修饰函数的参数和返回值, 甚至函数定义体,被const修饰的东西都受到强制保护,可以预防意外的变动,能提高程序的健壮性 阅读全文

指针常量、常量指针

2022-11-13 11:58 by 钟铧若岩, 43 阅读, 收藏, 编辑
摘要: 1 #include <stdio.h> 2 #include <string.h> 3 4 int main(int argc, char **argv) { 5 printf("Hello, World!\n"); 6 7 int a = 10; 8 int a1 = 20; 9 //不能再修改 阅读全文

字符串函数以及宏定义

2022-11-13 11:41 by 钟铧若岩, 49 阅读, 收藏, 编辑
摘要: 最小值、以及平方的宏定义实现,注意()的使用 1 #include <stdio.h> 2 #include <string.h> 3 4 #define MIN(a,b) (a)<(b)?(a):(b) 5 #define SQRT(a) (a)*(a) 6 7 int main(int argc 阅读全文

在main函数执行完后,再执行其他方法

2022-11-13 11:24 by 钟铧若岩, 47 阅读, 收藏, 编辑
摘要: 方法如下: 1 #include <stdio.h> 2 3 int atexit(void(*function)(void)); 4 void fn1(void), fn2(void); 5 6 int main(int argc, char **argv) { 7 printf("Hello, 阅读全文

两个数字交换的方法

2022-11-12 23:48 by 钟铧若岩, 32 阅读, 收藏, 编辑
摘要: http://t.csdn.cn/yQZSj 阅读全文

C语言数据类型转型没有搞明白的点。

2022-11-12 23:33 by 钟铧若岩, 19 阅读, 收藏, 编辑
摘要: 程序员面试宝典第30页,请专家指导下,感谢! 1 #include <stdio.h> 2 #define product(x) ((x)*(x)) 3 int main(int argc, char **argv) { 4 printf("Hello, World!\n"); 5 6 unsign 阅读全文

运算符优先级

2022-11-12 23:14 by 钟铧若岩, 31 阅读, 收藏, 编辑
摘要: 1 #include <stdio.h> 2 #define product(x) ((x)*(x)) 3 int main(int argc, char **argv) { 4 printf("Hello, World!\n"); 5 6 int a = 5; 7 int b = 3; 8 int 阅读全文

I++与++I 面试题

2022-11-12 23:08 by 钟铧若岩, 27 阅读, 收藏, 编辑
摘要: 程序员面试宝典第28页,书中的答案是9,49 而正确的答案应该是,12,42 3*4 = 12 6*7 = 42 1 #include <stdio.h> 2 #define product(x) ((x)*(x)) 3 int main(int argc, char **argv) { 4 pri 阅读全文
点击右上角即可分享
微信分享提示