Files
BlogPosts/Collection/连~都忘记了的小知识.md

44 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
tags:
- C语言
- Linux
aliases:
- 小知识
日期: 2026/1/23
---
- 字符类型数字转整形数字要 `-'0'`
```c
char arr[10];
for(int i = 0;i < strlen(arr);i++)
num = num * 10 + arr[i] - '0';
```
- Linux重新加载配置文件命令
```shell
shource ~/.bashrc #重载bashrc文件
```
- Linux写脚本
```shell
vim mount_hgfs
sudo vmhgfs-fuse .host:/ /mnt/hgfs/ -o allow_other #填入命令
chmod +x mount_hgfs #增加执行权限
mv mount_hgfs /bin #移动到/bin路径下 以后使用 mount_hgfs 直接执行
```
- C语言`&&`运算符的左值为假时,右值不进行计算,同理`||`运算符左值为真右值不进行计算
- 按位异或`^a ^ b = c , a ^ c = b , b ^ c = a;`,可用于进行数的交换(省去中间值)
- C语言左移`<<`就是与2的x次方相乘右移为相除
- 简便运算后有括号`a *= 5+8 ==> a = a * (5 + 8)`,赋值运算符的优先级很低
- C语言中` ... `表示范围赋值
```c
int arr[10] = {[0 ...3] = 24, [6 ...9] = 12};
//or
switch (num)
{
case 90 ...100:
printf("LEVEL: A \n");
break;
default:
printf("What are you doing baby ? \n");
break;
}
```
- 函数的名称与数组的名称一样,是函数的首地址