当前位置:网站首页>C language array and bubble sort
C language array and bubble sort
2022-07-28 20:00:00 【Embedded Xiaobai aspires to be a boss】
1、 Array
integer array 、 Character array 、 Two dimensional array
1.1 Concept
A set of elements with the same data type
characteristic :(1) Same data type (2) Address continuous
As shown in the figure above , The address of the array is continuous
1.2 Definition
Storage type data type Variable name ;
int a;// An integer variable is defined
Storage type data type Array name [ Number of elements ];
int a[5];// An array is defined , Array has 5 Elements
Storage type :auto、register、static、extern
data type : The data type of each element in the array
Data type of array : data type [ Number of elements ] int [5]
data type : Removing the variable name is the data type
Array name : Address of the first element of the array ( Entire array )
Number of elements : It must be a definite number ( integer constants )
1.3 Initialization of an array
1.3.1 Partial initialization
int a[5] = {1,2,3};
a[0] = 1 ,a[1] = 2, a[2] =3, a[3] = ? ,a[4] = ? a[5] = ?//error
summary : When the array is partially initialized , If it's not assigned , The default is 0, So we use this feature to clear the array
1.3.2 All initialization
int a[5] = {1,2,3,4,5};
int b[ ] = {1,2,3};// The number of elements of the array is determined by the specific number assigned later
- If the array is defined inside the function body , Not initialized , Its value is random
- If the array is defined outside the function , Not initialized , Its value is 0
- If you use static modification , Not initialized , Its value is 0
1.4 Array access
Array name [ Subscript ];
Be careful : The subscript of an array is from 0 At the beginning
1.5 Array input 、 Output
1.6 Bubble sort
thought : Compare from left to right , If the former number is larger than the latter one , Just swap places , Otherwise unchanged
2、 A character array
The essence of character arrays : It's a string , With ‘\0’ As a Terminator
Storage type data type Array name [ Number of elements ];
char str[6] = {‘h’,’e’,’l’,’l’,’o’,’\0’}; // At most 5 Elements , Leave a place for ’\0’
char str[6] = “hello”;
char str[6] = {“hello”};
Clear the character array :char str[6] = {‘\0’};
2.1 String output function
puts( Array name );
function : Print the string in the array to the terminal , And automatically add and wrap lines
Be careful : encounter ’\0’ end
2.2 Input function of string
gets( Array name );
function : Put the string entered by the keyboard into the array , And automatically add ’\0’
Be careful : No cross-border inspection , So don't type more
2.3 summary
2.3.1 scanf and gets The difference between
gets It ends with carriage return , however scanf By return 、Tab Key and space as terminators
buffer :
gets: When you finish inputting the string , The buffer will be emptied automatically
scanf: When you finish inputting the string , Spaces will be left in the buffer 、 enter 、Tab key
Be careful :gets First check whether there is any residual content in the buffer , If there is , Just take it and use it , Otherwise input
scanf Is a standard input function , You can only get the value by entering at a time
2.3.2 puts and printf The difference between
puts Line breaks will be automatically added , and printf Can't
边栏推荐
- 2022年下半年系统集成项目管理工程师认证8月20日开班
- Verification of chip power consumption performance: from dilemma to transcendence
- Application skills of programming rising and falling edge instructions of botu 1200/1500plc (bool array)
- leetcode day4 部门工资最高的员工
- Leetcode Day1 score ranking
- CDGA|工业互联网行业怎么做好数据治理?
- Servlet learning notes
- [网络]跨区域网络的通信学习IPv4地址的分类和计算
- Crawl IP
- In order to develop high-end photoresist, Jingrui Co., Ltd. invested 75million yuan to purchase SK Hynix ASML lithography machine
猜你喜欢

通信网络基础知识01

shared_ PTR and make_ Use of shared

In the second half of 2022, the system integration project management engineer certification starts on August 20

Theoretical knowledge of digital image (I) (personal analysis)

Saltstack system initialization

Thoroughly understand bit operations -- and (&), not (~), or (|), XOR (^)

软考中级(系统集成项目管理工程师)高频考点

How does app automated testing achieve H5 testing

架构基本概念和架构本质

Deploy LNMP automatically with saltstack
随机推荐
The peak rate exceeds 2gbps! Qualcomm first passed 5g millimeter wave MIMO OTA test in China
基于C语言的信息管理系统和小游戏
党员故事|李青艾用漫画带动农民增收致富
Redis笔记
Getting started with enterprise distributed crawler framework
Article translation software - batch free translation software supports major translation interfaces
MySQL性能测试工具sysbench学习
How does app automated testing achieve H5 testing
Deploy ZABBIX automatically with saltstack
There are five certificates in the soft examination advanced examination, which is more worth taking?
OpenOCD如何通过stlink直接下载程序到stm32板子(已解决)
【NPP安装插件】
English translation Portuguese - batch English conversion Portuguese - free translation and conversion of various languages
In the second half of 2022, the system integration project management engineer certification starts on August 20
Kubeedge releases white paper on cloud native edge computing threat model and security protection technology
leetcode day3 查找重复的电子邮箱
STC12C5A60S2 function description (STC12C5A60S2 is triggered by default)
MySQL8 tmp_ table_ Size and Max_ heap_ table_ size
MySQL8 tmp_table_size和max_heap_table_size
BeanFactory not initialized or already closed - call ‘refresh‘ before accessing beans via the Applic