in Programming
2,249 views
9 votes
9 votes

(int *) a means the base address of the array a ,(int *) a+1 means the address of 2nd element in the array. or base address of 2nd row of the array ? please clear this doubt i am facing problems in these type of question or if anyone knows basics of these types problems please explain that one.

  1.   1, 1, 1, 1
    2, 2, 2, 2
    3, 3, 3, 3
    2, 2, 2, 2 
    3, 3, 3, 3
    4, 4, 4, 4
      1, 1, 1, 1
    2, 3, 2, 3
    3, 3, 3, 3
    2, 3, 2, 3
    3, 3, 3, 3
    4, 4, 4, 4
  2.   1, 1, 1, 1
    2, 4, 2, 4
    3, 3, 3, 3
    2, 4, 2, 4
    3, 3, 3, 3
    4, 4, 4, 4
  3.   1, 1, 1, 1
    2, 4, 2, 4
    3, 0, 3, 0
    4, 2, 4, 2
    5, 5, 5, 5
    6, 0, 6, 0
in Programming
2.2k views

1 comment

Plz explain for

i = 1,  j=0

i. = 1 , j= 1

i.  = 1,  j= 2

I am not understand plz explain??
0
0

1 Answer

13 votes
13 votes
Best answer

let int *p = &i;

what it means, address of the integer i is stored in the p. ===> value of p = address of i.

∴ if you use p to require value, then it gives the address of the integer i.

 

ARR is a two dimensional array.

therefore it is a collection of 1-D array's. when you specified as value of ARR then it returns the base address of 1-D array.

 

for clarity image https://drive.google.com/open?id=1xGGZKaGH582n_aqwWOgyeGssxpYdjuRB

 

Note that, *(*(p+i)+j) = p[i][j]; and *(*(p+j)+i) = p[j][i];

 

when i=0

   when j=0 ===> the printf function prints 1,1,1,1

   when j=1 ===> the printf function prints 2,2,2,2

   when j=2 ===> the printf function prints 3,3,3,3

 

when i=1

   when j=0 ===> the printf function prints 2,2,2,2

   when j=1 ===> the printf function prints 3,3,3,3

   when j=2 ===> the printf function prints 4,4,4,4

selected by

4 Comments

you said that :

*(*(p+i)+j) = p[i][j]; and *(*(p+j)+i) = p[j][i];

but if we take i=0,j=1  than p[0][1]=2 is not equal to p[1][0]=4 thus the  answer should be 2,4,2,4 than why the answer is 2,2,2,2 please explain
0
0
You mistaken while understanding what is p[1].
0
0

Very well explained @ShaikMasthan

 

If in question like below

static int *p[]={a,a+1,a+2};

then

output like below

 

1 1 1 1
2 4 2 4
3 garbage 3 garbage
4 2 4 2
5 5 5 5
6 garbage 6 garbage

 

Please, correct if I am wrong.

0
0