C study notes[3]

文章目录

operatons

  1. the fundamental operators such as +,-,* in C language can be simply manipulated.
c 复制代码
int sum = 5 + 3;  // sum = 8
int difference = 10 - 4;  // difference = 6
int product = 6 * 7;  // product = 42

the operator / was left to introduce just a moment because that it's special as follows.

c 复制代码
5/2=2
5.0/2.0=2.5
5/2.0=2.5
c 复制代码
int quotient = 15 / 4;  // quotient = 3 (integer division)
float result = 15.0 / 4;  // result = 3.75

the operator % can get the remainder after division

c 复制代码
int remainder = 15 % 4;  // remainder = 3
  1. ++ accomplishes the operation of increasing by 1 by itself
c 复制代码
int x = 1;
int y= x++;

as similar principle, -- apply the compuation of decreasing by 1 by itself.

c 复制代码
int x = 1;
int y= x--;

--x and ++x mean that the final result is returned affter these operation have finished.

  1. The sizeof operator is a compile-time unary operator that returns the size (in bytes) of a variable, data type, or expression.
c 复制代码
sizeof(type)
sizeof(expression)
sizeof variable_name

loops

  • Executes a block of code as long as a condition is true.
c 复制代码
int i = 0;
while (i < 5) {
    printf("%d ", i);
    i++;
}
// Output: 0 1 2 3 4
  • do-while loop:as similar as while,the condition of loop which is true decides to continue loop but there is an obvious difference that the do-while loop inspects the loop's condition after finishing the block of the loop one time ,no matter whether the condition was met .
c 复制代码
int i = 0;
do {
    printf("%d ", i);
    i++;
} while (i < 5);
// Output: 0 1 2 3 4
  • for Loop
c 复制代码
for (int i = 0; i < 5; i++) {
    printf("%d ", i);
}
// Output: 0 1 2 3 4
  • break - Exits the loop immediately
c 复制代码
for (int i = 0; i < 10; i++) {
    if (i == 5) break;
    printf("%d ", i);
}
// Output: 0 1 2 3 4
  • continue - Skips the current iteration and continues with the next
c 复制代码
for (int i = 0; i < 5; i++) {
    if (i == 2) continue;
    printf("%d ", i);
}
// Output: 0 1 3 4

references

  1. deepseek
相关推荐
d111111111d19 分钟前
C语言中,malloc和free是什么,在STM32中使用限制是什么,该如何使用?
c语言·开发语言·笔记·stm32·单片机·嵌入式硬件·学习
李白同学27 分钟前
Linux:调试器-gdb/cgdb使用
linux·服务器·c语言·c++
黎雁·泠崖2 小时前
指针家族高阶篇:字符指针、数组指针、函数指针及转移表应用
c语言·开发语言
未来之窗软件服务2 小时前
幽冥大陆(五十七)ASR whisper-cli命令行使用 C语言—东方仙盟筑基期
c语言·开发语言·whisper·仙盟创梦ide·东方仙盟·东方仙盟自动化·东方仙盟商业开发
程芯带你刷C语言简单算法题2 小时前
Day33~实现一个算法来识别一个字符串。
c语言·算法·c
yyy(十一月限定版)3 小时前
c语言——二叉树
c语言·开发语言·数据结构
IT方大同4 小时前
循环结构的功能
c语言·数据结构·算法
黎雁·泠崖4 小时前
吃透指针通用用法:回调函数与 qsort 的使用和模拟
c语言·开发语言
脏脏a4 小时前
聊聊 C 里的进制转换、移位操作与算术转换
c语言·开发语言·移位操作符
xie_pin_an4 小时前
深入解析 C 语言排序算法:从快排优化到外排序实现
c语言·算法·排序算法