in Programming in C
1,448 views
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;

}

in Programming in C
by
1.4k views

4 Comments

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
4
"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
3
i got 1, 3 as output (i know it is wrong)
can anybody suggest me source to this type of question
0
0
What is the size of int you are considering
0
0

1 Answer

9 votes
9 votes
Best answer

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

selected by

2 Comments

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
1
reshown by
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
0

Related questions