当前位置:网站首页>[dish of learning notes dog learning C] detailed array name
[dish of learning notes dog learning C] detailed array name
2022-07-21 03:15:00 【Jiang Junzhu】
List of articles
One 、 Array name
// What is the array name ?
// The array name is the address of the first element of the array
// But there are 2 Exceptions
//1.sizeof( Array name ) - The array name represents the entire array - It calculates the size of the entire array , Unit is byte
//2. & Array name - The array name represents the entire array - It takes out the address of the entire array
int main() {
int arr[10] = {
0 };
printf("%p\n", &arr);// &arr What we get is the address of the array
printf("%p\n\n", &arr + 1);
printf("%p\n", arr);
printf("%p\n\n", arr + 1);
printf("%p\n\n", &arr[0]);
int sz = sizeof(arr);// The array name represents the entire array
printf("%d\n\n", sz);
printf("%p\n", &arr[0]);
printf("%p\n", &arr);// The array name is the address of the first element
return 0;
}
As can be seen from the figure above , The difference between the first group of addresses is in octal 28, To convert to decimal is to 40, It's an array arr Sum of all element sizes , therefore &arr What we get is the address of the array
, The second group of addresses corresponds to the first group , prove &arr What we get is the address of the array
;
Print out 40, explain sizeof( Array name )
Represents the entire array ,sizeof( Array name )
It calculates the size of the entire array , So the printed value is 40
;
The address number of the last group is the same , Note that the array name is the address of the first element of the array .
Two 、 Arrays as function arguments
notes : Bubble sorting idea is to compare two adjacent elements , And may be exchanged .
void bubble_sort(int arr[], int sz) {
// Shape parameter arr The essence is the pointer
// Determine the number of trips
int i = 0;
for (i = 0; i < sz - 1; i++) {
// A bubble sorting process
int j = 0;
for (j = 0; j < sz - 1 - i; j++) {
if (arr[j] > arr[j + 1]) {
// In exchange for
int tmp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = tmp;
}
}
}
}
int main() {
int arr[] = {
9,8,7,6,5,4,3,2,1,0 };
// Sort in ascending order - Bubble sort
// Count the number of array elements
int sz = sizeof(arr) / sizeof(arr[0]);
bubble_sort(arr, sz);
return 0;
}
边栏推荐
- 基于SSM实现水果蔬菜商城管理系统
- 谷粒学院使用nacos注册gateway网关时候报错503
- CTFshow-web入门信息收集-wp(1-20) (详解)
- Usage and configuration of Apache Doris ODBC MySQL appearance under Ubuntu
- 【学习笔记之菜Dog学C】初识操作符和原码、反码、补码
- In depth understanding of MySQL execution process and execution sequence
- 文件权限管理
- Apache Doris Grafana监控指标介绍
- 【学习笔记之菜Dog学C】结构体初阶
- Graduation season -- use technology of various application scenarios
猜你喜欢
SIGIR‘22 推荐系统论文之对比学习篇
Mysql 我随手造200W条数据,给你们讲讲分页优化。
[scientific literature measurement] analysis and visualization of readability indicators of Chinese and English literature titles and abstracts
CV-Paper【1】:Deep Residual Learning for Image Recognition
ZigBee safety overview
ES6中Symbol、迭代器和生成器基本语法
化工企业如何选择双重预防机制数字化服务商
Rpc:thrift framework
LabVIEW中的自动保存功能
Apache Doris binlog Load use Methods and Examples
随机推荐
Apache Doris Oracle ODBC appearance guide under CentOS
毕业季--各应用场景案例使用技术
A. Log Chopping
LeetCode编程实践——腾讯精选50题 (一)
Apache Doris uses the Prometheus alertmanager module to send exception information to the nail alarm group
Implementation of fruit and vegetable mall management system based on SSM
蓝桥杯2020年第十一届国赛真题-天干地支
试题 D: 修剪灌木
Understand and apply continuous deployment Argo CD
Asynchronous processing of readfile blocking
Towards Representation Alignment and Uniformity in Collaborative Filtering
Binary tree implementation (generate binary tree according to hierarchical array)
Transform streams into data products
【C】 C语言入门
30 spark introduction: Spark Technology stack explanation, partition, system architecture, operator and task submission method
Apache Doris ODBC外表之Postgresql使用指南
QT quick 3D physics in QT 6.4
一文了解 NebulaGraph 上的 Spark 项目
Visual Studio 开发环境的配置
[sort] bucket sort and cardinal sort