当前位置:网站首页>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
边栏推荐
- 11. Learn MySQL union operator
- Nokia expands its 5g agreement with BT and will become its largest wireless access device supplier
- There are five certificates in the soft examination advanced examination, which is more worth taking?
- MySQL 8 creates master-slave replication based on Clone
- Basic concept and essence of Architecture
- 个人博克系统登录点击图形验证码的集成与实现
- 云原生编程挑战赛火热开赛,51 万奖金等你来挑战!
- shared_ PTR and make_ Use of shared
- 数字滤波器设计——Matlab
- Getting started with enterprise distributed crawler framework
猜你喜欢

How many types of rain do you know?
![[NPP installation plug-in]](/img/6f/97e53116ec4ebc6a6338d125ddad8b.png)
[NPP installation plug-in]

Codeignier framework implements restful API interface programming

Basic knowledge of communication network 01

How does app automated testing achieve H5 testing

Cloud computing notes part.1 - system management

“中国网事·感动2022”二季度网络感动人物评选结果揭晓

11. Learn MySQL union operator

Concurrent programming, do you really understand?

Saltstack configuration management
随机推荐
STC12C5A60S2 function description (STC12C5A60S2 is triggered by default)
Servlet learning notes
Leetcode Day2 consecutive numbers
Source insight project import and use tutorial
Leetcode day2 连续出现的数字
NPM installing and uninstalling global packages
Why is there no log output in the telnet login interface?
shared_ptr 和 make_shared 的使用
In the second half of 2022, the system integration project management engineer certification starts on August 20
MySQL8 基于clone创建主从复制
Information management system and games based on C language
There are five certificates in the soft examination advanced examination, which is more worth taking?
Preliminary learning function (3rd blog)
MySQL8 tmp_table_size和max_heap_table_size
CodeIgnier框架实现restful API接口编程
Saltstack system initialization
时间转日期的sql语句应该怎么写?
[NPP installation plug-in]
There is a 'single quotation mark' problem in the string when Oracle inserts data
Overcome the "fear of looking at teeth", and we use technology to change the industry