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
相关推荐
啊?啊?3 小时前
C/C++练手小项目之倒计时与下载进度条模拟
c语言·开发语言·c++
超级大福宝12 小时前
使用 LLVM 16.0.4 编译 MiBench 中的 patricia遇到的 rpc 库问题
c语言·c++
闭着眼睛学算法15 小时前
【华为OD机考正在更新】2025年双机位A卷真题【完全原创题解 | 详细考点分类 | 不断更新题目 | 六种主流语言Py+Java+Cpp+C+Js+Go】
java·c语言·javascript·c++·python·算法·华为od
麦麦在写代码16 小时前
动态内存管理 干货2
c语言
say_fall16 小时前
C语言底层学习(2.指针与数组的关系与应用)(超详细)
c语言·开发语言·学习
祐言QAQ16 小时前
(超详细,于25年更新版) VMware 虚拟机安装以及Linux系统—CentOS 7 部署教程
linux·运维·服务器·c语言·物联网·计算机网络·centos
Ziyoung16 小时前
【探究】C语言-类型转换问题
c语言
JasmineX-119 小时前
数据结构——静态链表(c语言笔记)
c语言·数据结构·链表
学不动CV了20 小时前
ARM单片机中断及中断优先级管理详解
c语言·arm开发·stm32·单片机·嵌入式硬件·51单片机
番茄大杀手21 小时前
C/C++柔性数组
c语言·柔性数组