In the following program, Here ptr
Has been declared as a pointer to an integer pointer and assigned the base address of the array p[]
, which has been declared as an array of integer pointer. Suppose ptr
contains the address 9016
(suppose the starting address of p is 9016) before ptr
is incremented and after ptr++
, it will contain the value 9020 (suppose int takes 4 bytes).
So ptr-p
should give the output as 4 i.e (9020-9016=4). But it is giving output as 1 . why?
#include<stdio.h>
int main()
{
static int a[]={0,1,2,3,4};
static int *p[]={a,a+1,a+2,a+3,a+4};
int **ptr=p;
ptr++;
printf("%d",ptr-p);
return 0;
}