691 views
2 votes
2 votes
main(){

int a[2][3][2]={ { {1,2},{9,8},{3,7} },{ {2,3},{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]);

}

A) 3 3 1

B) 3 6 1

C) 6 6 1

D) 1 1 1

Plz explain

2 Answers

3 votes
3 votes
a[1][0][0]-a[0][0][0]=2-1=1
a[1][0]-a[0][0]=(address of a[1][0][0]- address of a[0][0][0])/size(int)=6*sizeof(int)/sizeof(int)=6;
(note: here a[1][0] is of type int *(i.e, starting address of 1D array or Integer pointer ) hence we divide by sizeof(int) )
a[1]-[0]=(address of a[1]-address of a[0])/ sizeof(int[2])=6*sizeof(int)/sizeof(int[2])=3
(note: here a[1] is of type int (*)[2](i.e, starting address of 2D array or pointer to a Integer array int[2]) hence we divide by sizeof(int [2]) )
Hence the answer is B
edited by

Related questions

5 votes
5 votes
2 answers
1
Mandeep Singh asked Oct 22, 2016
18,320 views
#include <stdio.h int main() { int y = 2; int z = y +(y = 10); printf("%d\n", z); }
2 votes
2 votes
3 answers
2
komal07 asked Apr 10, 2015
1,371 views
What is the output of the following $C$ code segment?# define product (a, b) a * b main() { int x=5, y=2; print f("%d", product{x+4, y-3}); }$10$$-9$$15$Error.
1 votes
1 votes
1 answer
3
Archies09 asked Apr 23, 2017
3,277 views
What will be the output of the program?#include<stdio.h int addmult(int ii, int jj) { int kk, ll; kk = ii + jj; ll = ii * jj; return (kk, ll); } int main() { int i=3, j=4...
0 votes
0 votes
1 answer
4