array [1] [2]和array [1,2]有什么区别?

编程入门 行业动态 更新时间:2024-10-20 15:45:38
本文介绍了array [1] [2]和array [1,2]有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果我的二维数组是int array [4] [5] = {1,2,3,4,5,6,7,8,9,0,11,12,13,14,15,16 ,17,18,19,20};

if my two dimensional array is int array[4][5]= {1,2,3,4,5,6,7,8,9,0,11,12,13,14,15,16,17,18,19,20};

当我打印位置时:printf(%d \ n",array [2,0]);.这是在不提供&的情况下打印值的地址.但是如果我这样打印:printf(%d \ n",& array [2] [0]);它是值的打印地址.正如我给出的&它打印地址.但两者的地址不同.但是如果我打印printf(,:%d \ n",array [3,0]);它正在打印数组[2,0]的相同地址.

when I print a position: printf("%d\n",array[2,0]);. this is printing the address of the value without giving the &. but if I print like this: printf("%d\n",&array[2][0]); it is printing address of the value. As I have given the & it prints the address. but both the address are different. but if I print printf(",:%d\n",array[3,0]); it is printing the same address of array[2,0].

[2] [0]和[2,0]访问数组元素之间的区别是什么.

what is the difference between [2][0] and [2,0] accessing the array elements.

推荐答案

阅读有关逗号运算符的信息. array[2][0]正在访问第三行第一列的元素. array[2,0]首先执行操作(2,0)(返回0),因此等效于array[0],后者返回数组的第一行(实际上是&array[0][0],因为它会衰减为指针).

Read about comma operator. array[2][0] is accessing element at third row, first column. array[2,0] is first executing operation (2,0) (which returns 0) and thus is equivalent to array[0], which returns the first row of array (actually &array[0][0] because it decays to a pointer).

更多推荐

array [1] [2]和array [1,2]有什么区别?

本文发布于:2023-06-08 21:28:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/589371.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有什么区别   array

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!