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
相关推荐
C++ 老炮儿的技术栈6 小时前
include″″与includ<>的区别
c语言·开发语言·c++·算法·visual studio
小龙报7 小时前
《彻底理解C语言指针全攻略(6)-- qsort、sizeof和strlen》
c语言·开发语言·职场和发展·创业创新·学习方法·业界资讯·visual studio
无限进步_9 小时前
C语言文件操作全面解析:从基础概念到高级应用
c语言·开发语言·c++·后端·visual studio
_码力全开_9 小时前
P1005 [NOIP 2007 提高组] 矩阵取数游戏
java·c语言·c++·python·算法·矩阵·go
dllxhcjla10 小时前
07 标识符命名规则
c语言
杨福瑞11 小时前
C语言数据结构:算法复杂度(2)
c语言·开发语言·数据结构
DuHz11 小时前
C程序中的循环语句
c语言·嵌入式硬件·软件工程
一念&12 小时前
每日一个C语言知识:C 指针
c语言·开发语言
deng-c-f14 小时前
Linux C/C++ 学习日记(22):Reactor模式(二):实现简易的webserver(响应http请求)
linux·c语言·网络编程·reactor·http_server
朱嘉鼎16 小时前
C语言之可变参函数
c语言·开发语言