当前位置:网站首页>C language - deep understanding of arrays
C language - deep understanding of arrays
2022-06-22 06:53:00 【Spadefish】
Why is the first subscript of an array from 0 Start ?

Because the array address must be calculated from 1 At the beginning, we have to take one more step , from 0 Start , It will be more efficient
#include <stdio.h>
#include <math.h>
void foo(int ary[])
{
ary++;
}
int main(int argc,char* argv[])
{
// Consistency and continuity
// Array name ary It's No 0 Address constants for elements
int ary[5] = {
1,2,3,4,5};
foo(ary); //foo(0x18ff34)
printf("%08x\r\n",ary);//ary It's a constant , So we can't ary++
/* Arrays are random access data structures type ary[N] = ...; int n = ...; ary[n] address is: (int)ary + sizeof(type)*n */
/* printf("%d\r\n",&ary[2]);// Subscript access operator printf("%d\r\n",(int)ary + sizeof(int)*2); printf("%d\r\n",&ary[argc]); printf("%d\r\n",(int)ary + sizeof(int)*argc); printf("%d\r\n",&ary[argc + 2]); printf("%d\r\n",(int)ary + sizeof(int)*( argc + 2)); */
printf("%08x\r\n",&ary[0]);//0x0018ff34
printf("%08x\r\n",&ary[8]);//0x0018ff54
printf("%08x\r\n",&3[ary]);//0x0018ff40
//0x00400000 -> 0x00905a4d ary[(0x00400000-(int)ary)/sizeof(int)] 0x00905a4d
// (00400000 - 0x0018ff3c )/4 + 2 = 9C033
printf("%08x\r\n",ary[(0x00400000-(int)ary)/sizeof(int)]);//0x00400000
system("pause");
return 0;
}
Function exchange numeric code
#include <stdio.h>
#include <math.h>
// Indirect access within a function will affect the actual parameters
// * [] -> These three operators generate indirect access
void foo(int x,int y)
{
int nTmp = x;
x = y;
y = nTmp;
}
int main(int argc,char* argv[])
{
int x = 8;
int y = 9;
foo(x,y); //foo(0x18ff34)
printf("%d\t%d\r\n",x,y);
system("pause");
return 0;
}
Array exchange numeric code :
#include <stdio.h>
#include <math.h>
// Indirect access within a function will affect the actual parameters
// * [] -> These three operators generate indirect access
void foo(int ary[])
{
int nTmp = ary[0];
ary[0] = ary[1];
aty[1] = nTmp;
}
int main(int argc,char* argv[])
{
// Consistency and continuity
// Array name ary It's No 0 Address constants for elements
int ary[5] = {
1,2,3,4,5};
foo(ary); //foo(0x18ff34)
printf("%d\t%d\r\n",ary[0],ary[1]);
system("pause");
return 0;
}
main Stack structure of :
Use to see argc Value , The bottom of the caller stack can be pushed 
The bottom and top of the caller stack will be initialized as local variables 0xcccccccc

The array is then initialized to 1,2,3,4,5
Press F11 Step into debugging
callee Stack structure of :

guess

Continue to press F11
Final value conversion 
Conclusion :
Indirect access within a function will affect the actual parameters
- [] -> These three operators generate indirect access
边栏推荐
- 【OpenAirInterface5g】ITTI消息收发机制
- Py's optbinning: introduction, installation and detailed introduction of optbinning
- 【OpenAirInterface5g】高层模块接口及itti实体线程创建
- Single cell literature learning (Part3) -- dstg: deconvoluting spatial transcription data through graph based AI
- In depth analysis of 20million OP events stolen by optimization (including code)
- OpenGL - Textures
- Tableau 连接mysql详细教程
- PgSQL batch insert
- 【5G NR】NGAP协议之NG Setup
- 深度解析Optimism被盗2000万个OP事件(含代码)
猜你喜欢

KV260的PMOD接口介绍

【OpenAirInterface5g】RRC NR解析(一)

C skill tree evaluation - customer first, making excellent products

Qt development simple Bluetooth debugging assistant (low power Bluetooth)

OpenGL - Textures
![[openairinterface5g] RRC NR resolution (I)](/img/04/fec30b5c86f29d82bd7d0b13293494.jpg)
[openairinterface5g] RRC NR resolution (I)

Neuron+eKuiper 实现工业物联网数据采集、清理与反控

Cesium加载3D Tiles模型

MySQL ifnull processing n/a

In depth analysis of 20million OP events stolen by optimization (including code)
随机推荐
[5g NR] mobile phone ID number IMEI and imeisv
[tp6] using the workman websocket
Record of problems caused by WPS document directory update
PgSQL batch insert
Shengxin literature learning (Part1) -- precision: a approach to transfer predictors of drug response from pre-clinical ...
Cactus Song - online operation (5)
代理模式与装饰模式到底哪家强
关于solidity的delegatecall的坑
Cesium加载3D Tiles模型
JS中如何阻止事件的传播
sessionStorage 和 localStorage 的使用
[openairinterface5g] project directory structure
【5G NR】手机身份证号IMEI与IMEISV
SQL injection vulnerability (x) secondary injection
6. 安装ssh连接工具(用于我们连接实验室的服务器)
JDBC query result set, which is converted into a table
6. install the SSH connection tool (used to connect the server of our lab)
Py's scorecardpy: a detailed introduction to the introduction, installation and use of scorecardpy
Which is the best agency mode or decoration mode
【5G NR】UE注册管理状态