4,030 views
0 votes
0 votes
#include <stdio.h>
int main()
{
int a[][3] = {1, 2, 3, 4, 5, 6};
int (*ptr)[3] = a;
printf("%d %d ", (*ptr)[1], (*ptr)[2]);
++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

2 Answers

Best answer
2 votes
2 votes
int *ptr[10];

This is an array of 10 int* pointers

int (*ptr)[10];

This is a pointer to an array of 10 int

  *(*a+1)   (*a)[1]  are two diffferent representation of a[0][1]

$int (*ptr)[3] $ // is nothing but  ptr[][]

$int (*ptr)[3]=a;$ // it stores address of a .

$(*ptr)[1]  $first element  // nothing but a[0][1]  which print 2
$(*ptr[2]) $ 2nd element. // // nothing but a[0][2] which print 3

$(++ptr)$ it is  increased .it access 2nd dimensional array 

$(*ptr)[1] $ first element  // nothing but a[1][1]  which print 5
$(*ptr[2])$  2nd element. // // nothing but a[1][2] which print 6

Output is $2,3,5,6$

http://stackoverflow.com/questions/13910749/difference-between-ptr10-and-ptr10

edited by
0 votes
0 votes
Ans should be 2& 3.....5&6 ...just u need to know

(*PTR)[s] can be written as *(*PTR +s)...u will able to solve problem...

Related questions

4 votes
4 votes
1 answer
1