当前位置:网站首页>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
边栏推荐
- Can China make a breakthrough in the future development of the meta universe and occupy the highland?
- How does app automated testing achieve H5 testing
- Read how to deploy highly available k3s with external database
- Edge detection and connection of image segmentation realized by MATLAB
- First blog
- Leetcode Day2 consecutive numbers
- Digital filter design matlab
- The opening price soared by 215%! Domestic signal chain chip enterprise Xinhai Technology landed on the scientific innovation board
- 一文读懂如何部署具有外部数据库的高可用 K3s
- MySQL8 Status Variables: Internal Temporary Tables and Files
猜你喜欢

【NPP安装插件】

How to write the SQL statement of time to date?

Article translation software - batch free translation software supports major translation interfaces

Cloud computing notes part.1 - system management

Deploy ZABBIX automatically with saltstack

How does app automated testing achieve H5 testing

JS batch add event listening onclick this event delegate target currenttarget onmouseenter OnMouseOver

个人博克系统登录点击图形验证码的集成与实现

党员故事|李青艾用漫画带动农民增收致富

云原生编程挑战赛火热开赛,51 万奖金等你来挑战!
随机推荐
There is a 'single quotation mark' problem in the string when Oracle inserts data
The cloud native programming challenge is hot, with 510000 bonus waiting for you to challenge!
Leetcode day3 employees who exceed the manager's income
Kubeedge releases white paper on cloud native edge computing threat model and security protection technology
MySQL8 tmp_table_size和max_heap_table_size
河北:稳粮扩豆助力粮油生产提质增效
leetcode day4 部门工资最高的员工
[网络]跨区域网络的通信学习路由表的工作原理
Design of air combat game based on qtgui image interface
云计算笔记part.2——应用管理
How does app automated testing achieve H5 testing
High beam software has obtained Alibaba cloud product ecological integration certification, and is working with Alibaba cloud to build new cooperation
Cdga | how can the industrial Internet industry do a good job in data governance?
Android section 13 03xutils detailed explanation of database framework (addition, deletion and modification)
CodeIgnier框架实现restful API接口编程
String中常用的API
Source code analysis of scripy spider
11、 学习MySQL UNION 操作符
中国能否在元宇宙的未来发展中取得突破,占领高地?
Saltstack configuration management