edited by
4,343 views
3 votes
3 votes

Assume sizeof an integer and a pointer is 4 byte. Output?

#include<stdio.h>
   #define R 10
#define C 20
   int main()
{
  int *p[R][C];
    printf("%d",sizeof(*p));
     printf("%d",sizeof(p));
   return 0;
}
edited by

4 Answers

5 votes
5 votes

Please discuss if wrong... 

4 votes
4 votes
int *p[10][20]

Here p is a 10*20 array of int pointers.

Size of p array = number of elements in array * size of each element

Assuming a 64 bit machine ,so any pointer size = 8bytes

So size of p = 10*20*8=1600

*p is an array of 20 int pointers

size of *p = number of elements in *p * size of each element = 20*8=160Bytes

 

If the question was int (*p)[10][20]

Then p is a pointer to 10*20 array of integers.

Since p is a pointer , sizeof(p) = 8bytes

*p is array of 10*20 integers.

Sizeof(*p)= number of elements in *p * size of each element = 10*20*4  (size of int = 4bytes) = 800Bytes.

Please someone correct me if I am wrong.
0 votes
0 votes
According to me i think p is pointing to an 2 dimension array which size is p[10] [20] right???

Now size of (*p)=means p[0] i.e size of pointer i.e 4 byte

Simple asking size of p i.e p is a pointer to an  2 dimension array  which size is 4 byte and return integer value ie 10*20*4=800 correct me plz if i am wrong??????
edited by
0 votes
0 votes
P is array of pointers. Each pointer will take 4byte in c.

*p is 20*4=80 size of zero th row. Now eash row contain 20 columns.

P means full array size 10*20*4=800.