in Programming in C
664 views
0 votes
0 votes

// C program to illustrate sizes of

// pointer of array

#include<stdio.h>

int main()

{

    int arr[] = { 3, 5, 6, 7, 9 };

    int *p = arr;

     

    printf("p = %p\n", p);

    printf("*p = %d\n", *p);

     

    printf("sizeof(p) = %lu\n", sizeof(p));

    return 0;

}

in Programming in C
664 views

2 Comments

The output shows sizeof(p)=8.But how? Since p is a pointer to array shouldn't it be 4 bytes?
0
0

I didn't get why printf("p = %p\n", p); <--this instruction not produced any output??

I checked output is as:

*p=3                                  // since, printf("*p = %d\n", *p);

sizeof(p) = 8                      //since, printf("sizeof(p) = %lu\n", sizeof(p));

0
0

1 Answer

1 vote
1 vote

Answer:

p = address of pointer p. (%p is used to print the address of pointer)

*p = 3 (it is the value at address which is stored in p) or (the data pointed by pointer p)

sizeof(p) = 8 (because it is the size of address stored in p. it is not the size of array)

  • address stored in p is of 8 bytes in 64 bit

  • address stored in p is of 4 bytes in 32 bit

 

 

Related questions