2 votes 2 votes What is the output of the following ? int main() { int arr[2][3][2]={1,2,3,4,5,6,7,8,9,10,11,12}; printf("%d%d", a[1]-a[0], a[1][0]-a[0][0]); return 0; } Programming in C programming-in-c pointers + – akb1115 asked Dec 7, 2017 akb1115 1.4k views answer comment Share Follow See all 4 Comments See all 4 4 Comments reply joshi_nitish commented Dec 7, 2017 reply Follow Share array will look like after putting explicit bracings arr[2,3,2] = {{{1,2},{3,4},{5,6}}, {{7,8},{9,10},{11,12}}} a[1]-a[0] = 3 // no. of hops diffrence on 2-D array a[1][0]-a[0][0] = 6 // no. of hops difference on 1-D array. note: in both the cases intial and final position are same(i.e element 1 and element 7), but what matters is which type of hopping you are using 2-D hopping or 1-D hopping. 4 votes 4 votes Shubhanshu commented Dec 7, 2017 reply Follow Share "a" is address and its type is 2D array address. a[1] - a[0] They are 1D array addresses so they should be divided by the size of 1 D array which is 4. so it is giving 3. a[1][0] - a[0][0] Here they are the type of variable addresses hence you need to divide by the size of variable which is 2, so the result will be 6. 3 votes 3 votes skyby commented Dec 7, 2017 reply Follow Share i got 1, 3 as output (i know it is wrong) can anybody suggest me source to this type of question 0 votes 0 votes Shubhanshu commented Dec 7, 2017 reply Follow Share What is the size of int you are considering 0 votes 0 votes Please log in or register to add a comment.
Best answer 9 votes 9 votes Ans will be 3, 6 (no matter what you take integer size - because that efferct will be normalized) I have taken 2 B. Just refer following diagram, a[1]-a[0] = 106-100/size of int = 6/2 = 3 a[1][0]-a[0][0] = 212 - 200/size of int = 12/2 = 6 Ashwin Kulkarni answered Dec 7, 2017 selected Dec 7, 2017 by akb1115 Ashwin Kulkarni comment Share Follow See all 2 Comments See all 2 2 Comments reply VS commented Dec 16, 2017 reply Follow Share Your answer is correct but representation is wrong ! Correct representation : 1 100 2 102 3 104 4 106 5 108 6 110 7 112 8 114 9 116 10 118 11 120 12 122 1 votes 1 votes Mayankprakash commented Jun 19, 2018 i reshown by Mayankprakash Jul 9, 2018 reply Follow Share Hi, Why are you considering Array size in previous question. As when we say a[0] --> its the value of the array we consider. Please help me in clearing my doubt how a[1]- a[0] is 106-100/size of int (2) is 3 .why are considering Address? 0 votes 0 votes Please log in or register to add a comment.