edited by
1,150 views
0 votes
0 votes
#include <stdio.h>
int main()
{
    int a[][3] = {1, 2, 3, 4, 5, 6};
    int (*ptr)[3] = a;  // LINE 5
    printf("%d %d ", (*ptr)[1], (*ptr)[2]); //LINE 6
    ++ptr;
    printf("%d %d\n", (*ptr)[1], (*ptr)[2]);
    return 0;
}

(a) 2 3 5 6 (b) 2 3 4 5 (c) 4 5 0 0 (d) none of the above

edited by

2 Answers

Best answer
5 votes
5 votes

Answer will be A) 2 3 5 6

To understand 4 and 5, you have to understand 2.

2 is declaring ptr, Here ptr is a pointer to an array of size 3. It means that when you write ptr++ it will jump 3 element. Hence The output. I think you got this now. 

selected by
1 votes
1 votes

ans should be a) 2 3 5 6

in the following line due to initialization of 6 elements array will be int a[2][3] from a[0][0] to a[2][3]

int a[][3] = {1, 2, 3, 4, 5, 6}; eqvt to int a[2][3]

next line 

int (*ptr)[3] = a;

 is pointer to 2 dimensional array with  initialized to array a so ptr[0] will point a[0][0] ptr[1] will point a[0][1] and so on  then ptr++ will take u 3 elements ahead so then ptr[0] will point 4 ptr[1] will point 5 and so on 

Related questions

0 votes
0 votes
1 answer
2
Desert_Warrior asked May 16, 2016
520 views
#include<stdio.h int a = 10; int main() { fun(); fun(); return 0; } int fun() { static int a = 1; printf("%d ",a); a++; return 0; }
0 votes
0 votes
1 answer
3
Desert_Warrior asked May 16, 2016
604 views
#include<stdio.h #include<stdlib.h int main() { char s[] = "Opendays2012"; int i = 0; while(*(s++)) i++; printf("%d",i); return 0; }(a) Segmentation Fault (b) Compile Err...
0 votes
0 votes
1 answer
4
Desert_Warrior asked May 16, 2016
407 views
#include <stdio.h int main(void) { char a[5] = { 1, 2, 3, 4, 5 }; char *ptr = (char*)(&a + 1); printf("%d %d\n", *(a + 1), *(ptr - 1)); return 0; }(a) Compile Error (b) 2...