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
相关推荐
Zwawa2 小时前
两根线怎么挂住一堆设备:I2C 协议原理
c语言·单片机·嵌入式
武子康3 小时前
h3.c 的两个权重槽,怎样把内存压力换成 SSD 等待
c语言·人工智能·agent
§ꦿCFོ༉1 天前
嵌入式八股—C语言入门学习(一)
c语言·编程语言·嵌入式八股文
沐晓时光1 天前
C语言入门,字符串和字符串函数知识讲解
c语言·开发语言
智者知已应修善业1 天前
【51单片机实现从下到上,从上到下,从中间到两边,两边到中间】2024-10-23
c语言·经验分享·笔记·单片机·嵌入式硬件·51单片机
布莱克6052 天前
C/C++ 中变量的声明与定义:区别、联系与常见误区
c语言·开发语言·c++·声明·定义
揽星河..2 天前
【C语言】底层程序设计
c语言·开发语言
揽星河..2 天前
【C语言】结构体
c语言·开发语言
唐青枫2 天前
C 语言 malloc() 详解与实战 Demo
c语言
揽星河..2 天前
【C语言】指针
c语言·开发语言