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
相关推荐
promising-w41 分钟前
【嵌入式C语言】六
c语言·开发语言
ankleless1 小时前
C语言(11)—— 数组(超绝详细总结)
c语言·零基础·数组·二维数组·自学·一维数组
草莓熊Lotso2 小时前
《吃透 C++ 类和对象(中):const 成员函数与取地址运算符重载解析》
c语言·开发语言·c++·笔记·其他
野生的编程萌新5 小时前
从冒泡到快速排序:探索经典排序算法的奥秘(二)
c语言·开发语言·数据结构·c++·算法·排序算法
谱写秋天15 小时前
FreeRTOS中断服务程序(ISR)详细讲解
c语言·freertos·isr
GUET_一路向前18 小时前
【C语言】解释形参void *data用法
c语言·开发语言·通用指针
pusue_the_sun19 小时前
数据结构——顺序表&&单链表oj详解
c语言·数据结构·算法·链表·顺序表
风铃7771 天前
c/c++ Socket+共享内存实现本机进程间通信
linux·c语言
John.Lewis1 天前
数据结构初阶(15)排序算法—交换排序(快速排序)(动图演示)
c语言·数据结构·排序算法