GATE CSE
First time here? Checkout the FAQ!
x
+1 vote
116 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 (13.3k points)  
edited by | 116 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 (56.6k points)  
selected by
@srestha,here if i want to point to address of 2..then what should i write??
&(*ptr)[1]


Top Users Aug 2017
  1. Bikram

    4990 Points

  2. ABKUNDAN

    4730 Points

  3. akash.dinkar12

    3488 Points

  4. manu00x

    3286 Points

  5. rahul sharma 5

    3166 Points

  6. makhdoom ghaya

    2510 Points

  7. just_bhavana

    2398 Points

  8. stblue

    2144 Points

  9. Tesla!

    2066 Points

  10. joshi_nitish

    1796 Points


25,022 questions
32,159 answers
74,902 comments
30,202 users