• edited by
1,959 views
7 7 votes

Consider the following C program

main()

{

int a[2][3][2]={{{1,2},{9,8},{3,7}},{{2,2},{1,4},{5,4}}}};

printf(“%d%d%d”, (a[1]-a[0]), (a[1][0]-a[0][0]), (a[1][0][0]-a[0][0][0]));

}

Which of the following represents the output of above program?

  1. $3\: 3\; 1$
  2. $3\; 6 \;1 $
  3. $6\;6\;1$
  4. $1\:1\:1$

3 Answers

Best answer
14 14 votes

Your answer is correct . It should be 361 only.
 

'

$a[1] - a[0] = \frac{112-100}{size of row} = \frac{12}{4} = 3$

$a[1][0] - a[0][0] = \frac{112-100}{size of element} = \frac{12}{2} = 6$

$a[1][0][0] - a[0][0][0] = 2-1 = 1$

Output : 3 6 1

• selected by
1 1 vote
6,6,6 should be the correct answer.
0 0 votes
ANS:-3,6,1

First of all a[1] is not equal to a[0][0][1]. a[0] is pointer of pointer which point to {1,2} and a[1] is point to {2,2}.

(PROOF:-If we print **a[o] then output is 1 and **a[1] then output is 2.)

so a[1]-a[0] is 3 beacause suppose address of {1,2} is 100 then address of {2,2} is 124 if int size consider 4. Then we add 3 in the adress of a[0] we get adress of a[1] because each { , } has size 8.so 100+8*3=124. so a[1]-a[0]=3.

simillarliy,a[1][0]-a[0][0]=6 because a[1][0] is adress of 2 and a[0][0] is adress of 1.suppose a[0][0] is 10 then a[1][0] is 34 each int has sze 4. 10+4*6=34

And a[1][0][0]-a[0][0][0]=1
Position:
Show:

Related questions

–2 –2 votes
0 0 answers
294
294 views
Deepak Yadav asked Sep 12, 2017
294 views
1 1 vote
1 1 answer
446
446 views
papesh asked Aug 11, 2016
446 views
How many maximum no.of edges possible in directed graph doesn't having cycle??
0 0 votes
0 0 answers
321
321 views
amit166 asked Nov 20, 2018
321 views
what is the difference between full binary tree,stricly binary tree,complete tree,perfect tree,alomst complete tree?
0 0 votes
0 0 answers
615
615 views
Khursheed Bhat asked Feb 19, 2018
615 views
I was asked sometime ago in an interview draw generalised form of AVL tree that will contain all four rotations of AVL tree. I got confused I tried to explain them such n...