随笔分类 - C语言
摘要:1.角度转复数,使用std::polar #include <iostream> #include <complex> #include <cmath> int main () { float theta = 45; float theta_pi = theta*(M_PI/180); std::c
阅读全文
摘要:1. #define MY_MACRO ... #ifdef MY_MACRO // 这部分代码会被预处理器处理 #else // 这部分代码会被预处理器忽略 #endif 2. int my_var = 1; #define MY_MACRO my_var ... #if defined(MY_M
阅读全文
摘要:代码: #include <io.h> std::vector<std::string> StoreActionServer::getFolderList(const std::string &path) { std::vector<std::string> folderList; //文件句柄 l
阅读全文
摘要:C: #include <string.h> 提供字符串操作函数 C++: #include <string> 提供一个字符串类,string
阅读全文
摘要:如下: 优先级 运算符 名称或含义 使用形式 结合方向 说明 1 [] 数组下标 数组名[常量表达式] 左到右 () 圆括号 (表达式)/函数名(形参表) . 成员选择(对象) 对象.成员名 -> 成员选择(指针) 对象指针->成员名 2 - 负号运算符 -表达式 右到左 单目运算符 (类型) 强制
阅读全文
摘要:总流程: 1.预处理(Preprocessing) 预处理用于将所有的#include头文件以及宏定义替换成其真正的内容; 将hello.c预处理输出hello.i文件 2.编译(Compilation) 将经过预处理之后的程序转换成特定汇编代码(assembly code)的过程; 在这个阶段中,
阅读全文
摘要:代码: #include <stdio.h> #include <string.h> #define N 1024 int main(int argc, char* argv[]) { FILE* fp; fp = fopen("file.txt", "w"); if(!fp){ printf("f
阅读全文
摘要:一、C语言: 1、输入 ①、scanf 遇到空格、回车和Tab键停止; 自动在输入字符串末尾加结束符; #include <stdio.h> int main(void){ int a,b,c; printf("input a,b,c\n"); scanf("%d%d%d",&a,&b,&c); p
阅读全文
摘要:代码: #include <stdio.h> #include <string.h> #define N 1024 char* fun(char* str, int m) { int totalLength = strlen(str); static char ret[N]; memset(ret,
阅读全文
摘要:原则: 能否正常返回这个值,要看这个值的内容或指向的内容是否被回收,导致空指针或者真实内容被擦除。【一旦返回值有指针或者地址,就需要着重考虑,而返回一个值是一般都可以的,可参考C++的临时变量】 下面对不同情况说明。 1、返回指向常量的指针 #include <stdio.h> char *retu
阅读全文
摘要:代码: #include <stdio.h> #include <string.h> #define bool char #define N 1024 #define W 64 bool isWord(char word[], int length) { bool ret = 1; int i; f
阅读全文
摘要:一般声明之后要初始化全为0,如下: #define ARRAY_SIZE_MAX (1*1024*1024) void function1() { char array[ARRAY_SIZE_MAX] = {0}; //声明时使用{0}初始化为全0,'\0'的码就是0 } void function
阅读全文
摘要:代码: #include <stdio.h> #include <string.h> #define NAME_LENGTH 256 #define PERSON_COUNT 3 struct Person { char name[NAME_LENGTH]; int moneyNum; }; voi
阅读全文
摘要:格式化表: 控制符说明 %d 按十进制整型数据的实际长度输出。 %ld 输出长整型数据。 %md m 为指定的输出字段的宽度。如果数据的位数小于 m,则左端补以空格,若大于 m,则按实际位数输出。 %u 输出无符号整型(unsigned)。输出无符号整型时也可以用 %d,这时是将无符号转换成有符号数
阅读全文
摘要:1、代码 #include <stdio.h> struct Person{ int a; double b; }; /*引用传递*/ void AliasFun(struct Person& person) { person.a = 100; person.b = 100.1; } /*指针传递*
阅读全文
摘要:用malloc和free;类似与C++的new和delete 代码: #include <iostream> #include <string> using namespace std; int main(int argc, char* argv[]) { void* ptr = (void*)ma
阅读全文
摘要:最近被这几个概念搞的头晕目眩,貌似懂了,但没完全懂。想通过理解的方式去搞清楚,而不是通过记性来记住。发现了一句万能钥匙,能解决大部分跟指针相关的概念问题: 指针存储的是地址。 1、代码 #include <stdio.h> int main(int argc, char *argv[]) { pri
阅读全文
摘要:C 库函数 int puts(const char *str) 把一个字符串写入到标准输出 stdout,直到空字符,但不包括空字符。换行符会被追加到输出中 参考菜鸟:https://www.runoob.com/cprogramming/c-function-puts.html
阅读全文
摘要:struct { unsigned char x1 : 2; unsigned char x2 : 2; unsigned char x3 : 2; unsigned char x4 : 2; } Bunch; /* sizeof(Bunch) => 1 */ struct { unsigned c
阅读全文