当前位置:网站首页>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
边栏推荐
- C skill tree evaluation - customer first, making excellent products
- JS中控制对象的访问
- -Bash: telnet: command not found solution
- OpenGL - Draw Triangle
- Data security practice guide - data collection security practice - data classification and classification
- sessionStorage 和 localStorage 的使用
- [openairinterface5g] project directory structure
- Py之scorecardpy:scorecardpy的简介、安装、使用方法之详细攻略
- 深度解析Optimism被盗2000万个OP事件(含代码)
- 【5G NR】UE注册管理状态
猜你喜欢

Tpflow V6.0.6 正式版发布

Correspondence between pytorch and torchvision

C技能树评测——用户至上做精品

OpenGL - Textures

MySQL ifnull processing n/a

Py's scorecardpy: a detailed introduction to the introduction, installation and use of scorecardpy
![[5g NR] UE registration management status](/img/e6/2415ea09b5faa4c5f204d8d67dbb6a.png)
[5g NR] UE registration management status

vue连接mysql数据库失败

5g-guti detailed explanation

Introduction to 51 Single Chip Microcomputer -- the use of Keil uvision4
随机推荐
Databricks from open source to commercialization
【OpenAirInterface5g】RRC NR解析(一)
iframe框架,,原生js路由
【openairinterface5g】项目目录结构
Rebuild binary tree
C技能树评测——用户至上做精品
[php]tp6 cli mode to create tp6 and multi application configurations and common problems
生成字符串方式
Which is the best agency mode or decoration mode
KV260的PMOD接口介绍
[M32] simple interpretation of MCU code, RO data, RW data and Zi data
自定义实现JS中的bind方法
仙人掌之歌——上线运营(4)
Introduction to 51 Single Chip Microcomputer -- minimum system of single chip microcomputer
C语言——深入理解数组
Introduction to 51 single chip microcomputer - 8x8 dot matrix LED
Leetcode--- search insertion location
Anaconda introduction, installation and use nanny level tutorial
迪进面向ConnectCore系统模块推出Digi ConnectCore语音控制软件
The song of cactus - marching into to C live broadcast (2)