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


Top Users Jun 2017
  1. Bikram

    3912 Points

  2. Arnab Bhadra

    1526 Points

  3. Hemant Parihar

    1502 Points

  4. Niraj Singh 2

    1501 Points

  5. Debashish Deka

    1480 Points

  6. junaid ahmad

    1432 Points

  7. pawan kumarln

    1286 Points

  8. Rupendra Choudhary

    1242 Points

  9. rahul sharma 5

    1240 Points

  10. Arjun

    1232 Points

Monthly Topper: Rs. 500 gift card
Top Users 2017 Jun 26 - Jul 02
  1. pawan kumarln

    418 Points

  2. akankshadewangan24

    334 Points

  3. Arjun

    272 Points

  4. Debashish Deka

    234 Points

  5. Abhisek Das

    230 Points


23,433 questions
30,149 answers
67,607 comments
28,486 users