GATE CSE
First time here? Checkout the FAQ!
x
+1 vote
79 views
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

asked in Programming by Veteran (12.9k points)  
edited by | 79 views
Is A) given answer??
correct..

1 Answer

+3 votes
Best answer
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;
1 2 3
4 5 6
 int (*ptr)[3] = a; // here ptr is pointer to an array of 3 integers.

At first ptr is pointing to first row. Say address of 1st row is 2000

So, (*ptr)[1]=*(2004)=2 and (*ptr)[2]=*(2008)=3

Now ++ptr is updating pointer to next row. So, Now ptr pointing to address 2000+3*4=2012

So, Now So, (*ptr)[1]=*(2016)=5 and (*ptr)[2]=*(2020)=6

answered by Veteran (53.1k points)  
selected by
@srestha,here if i want to point to address of 2..then what should i write??
&(*ptr)[1]


Top Users Apr 2017
  1. akash.dinkar12

    3782 Points

  2. Divya Bharti

    2696 Points

  3. Deepthi_ts

    2270 Points

  4. rude

    2142 Points

  5. Tesla!

    1888 Points

  6. Sanjay Sharma

    1692 Points

  7. Debashish Deka

    1668 Points

  8. Shubham Sharma 2

    1610 Points

  9. Prashant.

    1580 Points

  10. Arjun

    1570 Points

Monthly Topper: Rs. 500 gift card

22,135 questions
28,125 answers
63,467 comments
24,261 users