+ 1
What values are j-i and *j-*i actually subtracting ?? The answer i got was 3 30
main() { int arr[]={10,20,30,40,50,60}; int *i,*j; i=&arr[1]; j=&arr[5]; printf("%d %d",j-i,*j-*i); }
3 Antworten
+ 3
as we know
array is a collection of similar type data having continues memory allocation.............
int arr[]={10,20,30,40,50,60} ;
So what will happen
there is a continues memory allocation of arr
arr[0]. arr[1]. arr[2] arr[3]
[10]. [20]. [30]. [40].
arr[4]. arr[5]
[50]. [60]
let suppose base address of arr[0] index is 1000
than arr[1] is 1002
becoz integer take two byte....
next part in second comment
+ 3
Second part
pointer store the address of the
so what will happen
when you do this
i=&arr[1]
j=&arr[5]
Here what happen two memory creates which hold the address of
arr[1]
arr[5]
i. j
[1002] [1010]
if we do j-i the and is 8..
now remember this
size of integer is change according to the compiler you used.
in turboc integer take 2 bytes where in gcc integer take 4byte.
as we dont know the base address start at arr[0] we cant predict the answer is 8,4,3;
its total depending upon base address and integer size
...
now second ans.
i -->>1002
j-->>1010
but
*i. focus on the location of arr[1]
*J focus on the location of arr[5]
I.e 20. and 60..
so when you do this*j-*i= 40;
https://code.sololearn.com/cBPoT5vaJjvP/?ref=app
+ 1
thanks for the help