随笔分类 - C/C++
摘要:class B{public: explicit B(int x= 0,bool b = true);}void doSomething(B obj) B obj; doSomething(obj) //没有问题 doSomething(28) //有问题,doSomething入参应该是B类类型,
阅读全文
摘要:学习参考以下链接: https://blog.csdn.net/lf12345678910/article/details/49619177 https://www.cnblogs.com/xiaomanon/p/4210016.html
阅读全文
摘要:main.cpp #include <stdio.h> #include "g_test.h" extern bool testFunc(); bool __attribute__((weak))testFunc() { warnf("this is weak api\n"); return fal
阅读全文
摘要:1.文章链接如下,属于转载,如有问题请联系我删除: https://blog.csdn.net/xxxxxx91116/article/details/7446455?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMa
阅读全文
摘要:结构体 typedef struct Time { unsigned int second :6; // 秒 0-59 unsigned int minute :6; // 分 0-59 unsigned int hour :5; // 时 0-23 unsigned int day :5; //
阅读全文
摘要:#include <iostream> char * func0(char * str) { printf("func0 %s\n", str); return NULL; } char * func1(char *str) { printf("func1 %s\n", str); return N
阅读全文
摘要:规则:C语言中,当一维数组作为函数参数的时候,编译器总是把它解析成一个指向首元素首地址的指针。 当函数参数为多维数组时,可以将其看做是第一维的一维数组;如,func(int a[3][4]),此处的定义的指针类型为int (*p)[4];具体参考代码如下: 1.一维数组:#include <iost
阅读全文
摘要:#include <stdio.h> int main(int argn ,char *argv[]) { int a[5][5]; int (*p)[4]; p = a; printf("&p[4][2]:0x%x, &a[4][2]:0x%x\n", &p[4][2], &a[4][2]); p
阅读全文
摘要:#include <stdio.h> int main(int argn ,char *argv[]) { int buf[10] = {1,2,3,4,5,6,7,8,9}; int (*p1)[3] = &buf; int (*p2)[3] = buf; int * p3 = (int*)((i
阅读全文
摘要:编译器Visual C++ 6.0 1. #include <stdio.h> int main() { int i = 10; char *p = (char *)(0x0018FF44); *p = NULL;return 0; } 说明:0x0018FF44是i的地址; 运行完后,p 的值为0
阅读全文
摘要:c语言中做除法和取余操作有以下几点规定: q = a / b; r = a % b; 1. 最重要一点:q * b + r == a;即 商 乘以 除数 加上 余数 等于 被除数; 2. 改变被除数a 的正负号,希望商q 的符号也随之改变,但商q 的绝对值不会改变; 3. 余数和被除数的正负号相同;
阅读全文
摘要:1.逗号操作符 取逗号操作符中的最后一个值; 2.++,--作为后缀时,遇到逗号操作符时语句结束,进行后缀++运算; #include <stdio.h> #include <stdarg.h> int main(int argn ,char *argv[]) { int i = 3; int c
阅读全文
摘要:1.注释的两种方式:// 和 /* */ 2.编译器在预处理剔除注释时,会将注释剔除掉,然后然后空格替换掉; 如:以下三种注释方法都是正确的 1. int /**/i = 22; 2. char* s = "weiyouqing// hiii"; 3. //Ist it a \ valid comm
阅读全文
摘要:void chToInt(char t, unsigned int & tt){ switch (t) { case '0': tt = 0; break; case '1': tt = 1; break; case '2': tt = 2; break; case '3': tt = 3; bre
阅读全文
摘要:1.fork创建进程的使用 fork()返回值等于0时,表示创建子进程; fork()返回值大于0时,是主进程; #include<stdio.h> #include<stdlib.h> #include<sys/wait.h> #include<signal.h> void sig_handler
阅读全文
摘要:typedef struct test { char num[10]; double age; }; 1.基本概念 有四个概念需要理解:A、数据类型自身的对齐值: 指对该数据类型使用sizeof()操作符进行操作所得到的大小(单位,字节); 对于[unsigned] char类型的数据,其自身对齐值
阅读全文
摘要:1. 使用宏定义: #define SWAP(X, Y) (X) += (Y);(Y)=(X)-(Y);(X)=(X)-(Y); 2. 使用异或位操作符 int x = 21; int y = 12; x ^= y; y ^= x; x ^= y; #include <stdio.h> #inclu
阅读全文
摘要:1.为什么这样定义编译时候会报错:error: multiple storage classes in declaration specifiers typedef static int INT32 百度搜到的答案:typedef是存储类的关键字,和auto、static、register一样是存储
阅读全文
摘要:#include <stdio.h> #include <stdarg.h> typedef struct STest { char num; }stest_st, *stest_pst; int main(int argn ,char *argv[]) { const int iNum = 10;
阅读全文
摘要:#include <stdio.h> #include <stdarg.h> double testArgFunc(int num, ...) { // 创建一个参数列表 va_list valist; double sum = 0.0; // 为num个参数初始化valist va_start(v
阅读全文