当前位置:网站首页>C语言复习8
C语言复习8
2022-06-09 07:47:00 【樱木之】
C语言复习8
C语言学习,在这里推荐浙江大学翁恺老师的视频,慕课网网址:https://www.icourse163.org/learn/ZJU-9001?tid=9001#/learn/content。笔者的复习笔记也主要是根据该视频进行。本文的主要内容如下
- 程序设计与C语言
- 计算
- 判断
- 循环
- 循环控制
- 数据类型
- 函数
- 数组
数组;数组的运算;上机8; - 指针
- 字符串
- 结构类型
- 程序设计
- 文件
- 链表
refer
1.
8.1 数组
一、数组意义
数组用于记录很多数。可以使用变量名加中括号的形式实现,常见的形式如下:
二、数组的定义和使用
数组的定义需要定义类型、变量名称、元素数量,其中元素数量必须是整数。常见定义如下:
数组的元素在内存中是连续一次排列的,是一种容器,容器中的所有的元素都具有相同的数据类型,一旦创建其大小不能改变。下面以int a[10]为例子举例:
数组单元以a[0]开始计数,以0为首个索引。如果数组越界会报错segmentation fault。
8.2 数组的运算
一、数组的初始化
可以使用集成初始化,如int array[]={2, 2, 2, };。集成初始化中如果给出了数组大小,则其后元素会被初始化为0。
但是这里推荐使用遍历,如
int array[10];
for ( int i = 0; i<10; i++){
array[i] = 0;
}
二、数组的大小
数组大小计算常使用如下式子sizeof(a)/sizeof(a[0]);
三、数组赋值
数组变量本身并不能被赋值,如果需要对数组赋值,需要使用循环,依次将数组a的值赋值给数组b的值。
for ( int i = 0; i<length; i++ ){
b[i] = a[i];
}
四、数组遍历
使用上面那个for循环便可以遍历数组。
五、数组作为函数参数
函数传递的都是值,数组作为函数参数时,需要用另外一个参数传入数组的大小,不然函数体的本地变量的空间内就再也无从得知数组的大小。
六、二维数组
二维数组每一个嵌套后的大括号是一行的元素。如下1,2 就是第一行元素。
int a[][5] = {
{
1, 2},
{
2, 3},
}
边栏推荐
- Distributed message middleware -- Introduction to message queue
- [guide to stepping on the big pit] CSharp_ Process_ Prompt after running: no such file or pyinstaller prompt badzip, etc
- Use of Shopify port in EDI system of bridge of knowledge and Practice
- Use of qflags flag class
- China polytetrafluoroethylene (PCTFE) Industry Research Report (2022 Edition)
- Dbutil auxiliary class, manual commit transaction, metadata
- Sql Or NoSql,看完这一篇你就懂了
- R language through rprofile Site file, custom configuration of R language development environment startup parameters, shutdown parameters, use file Edit function edit configuration file
- At time_ What happens to TCP connections in wait status after SYN is received?
- Apache Web page and security optimization
猜你喜欢

Redis large key

The cumulative net worth of more than 1100 products fell below 0.8. Is the performance of private placement good this year?

2022年最新山西建筑安全员模拟题库及答案

mysql根据父节点递归查询所有子节点,List转树形结构工具类

Google browser F12 (developer tool) -- function introduction

Use of Shopify port in EDI system of bridge of knowledge and Practice
![[learning records of the first week in June] UU computer vision (1):3d Reconstruction & camera calibration](/img/7d/4830d5daa83ea2d39d2aeed7c3455c.png)
[learning records of the first week in June] UU computer vision (1):3d Reconstruction & camera calibration

MySQL: connection query

FTP service

Robot_ Framework: Variables
随机推荐
MySQL: grouping query
MySQL: merge query results and aliases
Simulated question bank and answers for the 2022 National latest fire facility operator (intermediate fire facility operator) examination
error converting YAML to JSON: yaml: line 10: found character that cannot start any token
Résumé des connaissances de base redis (hyper détaillé)
error converting YAML to JSON: yaml: line 10: found character that cannot start any token
pushmall推贴共享电商2022年5月份计划更新完成
mysql根据父节点递归查询所有子节点,List转树形结构工具类
"Sprint to Dachang foundation 2"
"Sprint to Dachang foundation 1"
Google browser F12 (developer tool) ---network
ftp服务
Fabric.js 激活输入框
MySQL: connection query
Global and China flywheel energy storage development research and future forecast report (2022 Edition)
PostgreSQL database replication - background first-class citizen process walreceiver extracts information
推送相关的总结
Pushmall push and paste sharing e-commerce plan update completed in May 2022
(十三)valgrind在ARM上交叉编译和内存泄漏检测
Talk about the ten mistakes often made in implementing data governance