[英]How the output is possible in the following?
'#include <stdio.h>
int main()
{
short arr[3][2]={3, 6, 9, 12, 15, 18};
printf("%d %d", *(arr + 1)[1], **(arr + 2));
}'
The output of the program is 15,15? 该程序的输出是15,15?
As per the operator precedence rule *(a+i)[j]
will be parsed as *((a + i)[j])
which is ultimately equivalent to *( *(a + i + j) )
. 根据运算符优先级规则
*(a+i)[j]
将被解析为*((a + i)[j])
,最终等同于*( *(a + i + j) )
。 So for i = 1
and j = 1
it will be *( *(a + 1 + 1) ) = *( *( a + 2) + 0) = a[2][0]
因此,对于
i = 1
和j = 1
,它将是*( *(a + 1 + 1) ) = *( *( a + 2) + 0) = a[2][0]
In the image given, It has a 3*2
matrix ie 3 rows and two 2 rows. 在给定的图像中,它具有
3*2
矩阵,即3行和2 2行。
*(arr+1)[1]
can be interpreted like this: *(arr+1)[1]
可以这样解释:
arr+1
gives the address of 2nd row 1st element. arr+1
给出第二行第一元素的地址。
(arr+1)[1]
gives the address of 3rd row 1st element. (arr+1)[1]
给出第三行第一元素的地址。
*(arr+1)[1]
gives the value present at this address *(arr+1)[1]
给出存在于该地址的值
Following is the example: 以下是示例:
void main(){
short arr[3][2]={3,6,9,12,15,18};
printf("%d %d %d %d", (arr ),(arr+1),(arr+1)[1],(arr +2));
}
Output: 输出:
-977229152 -977229148 -977229144 -977229144
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.