The Gateway to Computer Science Excellence
+4 votes
267 views

#include <stdio.h>

int main()
{
    int arr [2][3][2]= {{{1,2},{2,3},{4,5}},{{1,2},{2,3},{4,5}}};
      printf("%d %d", arr[1]- arr[0], arr[1][0]- arr[0][0]);

       return 0;
}

in Programming by Active (3.5k points)
edited by | 267 views
+2

answer will be 3, 6.

When you are doing arr[1]- arr[0] means you skip 3 rows each of 2 elements

When you are doing arr[1][0]- arr[0][0] means you skip 6 elements

0
@Anu sir i have a doubt..

suppose array starts at 100 .

a[1]-a[0]=112-100=12

but as a[1] and a[0] points to the entire array i.e 12 bytes. so 12/12=1.(skipping an array)

the difference between the 2 pointers should be according to the structure they are pointing to.

similarly for a[1][0] and a[0][0] points to the structure row (4 bytes).. so it should be 12/4=3.(skipping 3 rows)

what point am i missing.
0

a[1]-a[0]=112-100=12 this is correct,

but as a[1] and a[0] points to the entire array i.e 12 bytes. so 12/12=1.(skipping an array) why u done that

0
when a[1] (means you are outside 2-d array)  you skip 2-d array of 3 rows and each has size 4 byte .
i.e. 12/4 = 3
when you do a[1] [0] (means you are inside 2d array) means now you skip elements i.e. 12/ 2= 6
0
thaku sir:)

Please log in or register to answer this question.

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,324 answers
198,405 comments
105,169 users