当前位置:网站首页>【嵌入式C基础】第8篇:C语言数组讲解
【嵌入式C基础】第8篇:C语言数组讲解
2022-07-28 11:53:00 【黑猫学长呀】
1 概述
数组的基本概念:同一类型数据的集合
1.1 数组的定义
存储类型 数据类型 数组名[元素个数];
int a[5];
元素个数必须为常量,不能为变量
1.2 数组的初始化
int a;
数组初始化方法
全部初始化:
int a[5] = {1, 2, 3, 4, 5};
局部初始化:
int a[5] = {1, 2, 3};
注意:其他的即为0;
常用:int arr[5] = {0}; //初始化一个全部元素为0的数组,通常这个方法在清0数组时使用
默认初始化:
int a[] = {1, 2, 3, 4, 5};
int arr[] = {0}; //不常用的方法,这样相当于定了只有1个元素的数组,并且值为0
例子:
int a[5] = {0}; //对,局部初始化,所以全部即为0了
int a[] = {0}; //对,一个元素,初始化为0
int a[5] = {1, 2, 3, 4, 5}; //对
a = {1, 2, 3, 4, 5}; //错
初始化与赋值是不同的
初始化是程序在运行前由系统将变量值进行赋值,而赋值是在程序开始运行之后完成,赋值动作属于程序完成
int a;这个属于变量定义且不做初始化
int a=1;这个属于系统初始化,系统首先申请变量a,并且将这个单元放置初始值1
in
边栏推荐
- What if the right button of win11 start menu doesn't respond
- [graduation design] oscilloscope design and Implementation Based on STM32 - single chip microcomputer Internet of things
- Leetcode 42. rainwater connection
- 04 pyechars geographic chart (example code + effect diagram)
- Brother bird talks about cloud native security best practices
- LeetCode 移除元素&移动零
- C# 结构使用
- Flexpro software: measurement data analysis in production, research and development
- C# 泛型是什么、泛型缓存、泛型约束
- MySQL is always installed unsuccessfully. Just do it like this
猜你喜欢

Machine learning Basics - decision tree-12

Review the IO stream again, and have an in-depth understanding of serialization and deserialization

【嵌入式C基础】第4篇:运算符的使用
![[July 5 event preview] Flink Summit](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[July 5 event preview] Flink Summit

Science heavyweight: AI design protein has made another breakthrough, and it can design specific functional proteins

Jetpack Compose 完全脱离 View 系统了吗?

Phpstudy steps to quickly build a website (teach you to build it by hand)

05 pyechars basic chart (example code + effect diagram)

Introduction to border border attribute

Science 重磅:AI设计蛋白质再获突破,可设计特定功能性蛋白质
随机推荐
The 'name' attribute value associated with the element type 'item' cannot contain '& lt;' Character solution
SQL most commonly used basic operation syntax
What if the win11 folder cannot be opened
LeetCode 移除元素&移动零
C# 泛型是什么、泛型缓存、泛型约束
Siemens docking Leuze BPS_ 304i notes
Science 重磅:AI设计蛋白质再获突破,可设计特定功能性蛋白质
STM32 Development Notes - experience sharing
Leetcode 42. rainwater connection
IO流再回顾,深入理解序列化和反序列化
归并排序
Remove the plug-in of category in WordPress link
leetcode 376. Wiggle Subsequence
[Bi design teaching] STM32 and FreeRTOS realize low power consumption
FutureWarning: Indexing with multiple keys (implicitly converted to a tuple of keys) will be depreca
03 pyechars rectangular coordinate system chart (example code + effect drawing)
Machine learning practice - neural network-21
JSP自定义标签之自定义分页标签02
Scala transformation, filtering, grouping, sorting
Jetpack Compose 完全脱离 View 系统了吗?