int i,sum=0;
int array[8]={//You decide this};
int *a,*b,*c;
a = array;
b = &array[3];
c = &array[5];
c[-1] = 2;
array[1] = b[1]-1;
*(c+1) = (b[-1]=5) + 2;
sum += *(a+2) + *(b+2) + *(c+2);
printf("%d %d %d %d\n",
sum, array[b-a], array[c-a], *a-*b);
array[8]={ ?? };
what is array[8]?
Answer: Array is [1, 1, 5, 4, 2, 6, 7, 8 ]
Note1**: (if initial array ={1,2,3,4,5,6,7,8})
Note2: Please refer the below code and comments for the detailed explanation
#include <stdio.h>
int main(void) {
int i,sum=0;
int array[8]={1,2,3,4,5,6,7,8};
int *a,*b,*c;
a = array; // a will now point to base address of array
b = &array[3]; // b will now point to 4th element of array
c = &array[5]; // c will now point to 6th element of array
c[-1] = 2;
// c point to 6th element of array.
//Hence, 5th element of array will be updated to 2
//array={1,2,3,4,2,6,7,8}
array[1] = b[1]-1;
// array[1]=2-1=1 (as b[1]=2)
//array={1,1,3,4,2,6,7,8}
*(c+1) = (b[-1]=5) + 2;
// b points to 4th element of array. hence3rd element of array will be 5 (as b[-1]=5)
// c point to 6th element of array
// Here c+1 will point to 7th element of array
// Value of 7th element will be updated to 7;
// array={1,1,5,4,2,6,7,8}
sum += *(a+2) + *(b+2) + *(c+2);
//sum= 5 + 6+ 8 = 19
printf("%d %d %d %d\n",sum, array[b-a], array[c-a], *a-*b);
array[8] = 99 // in array "array", 8th index is outside the defined boundary. Hence this assignment will be ignored.
return 0;
}
Note3:Refer Screenshot for code indentation
The Output of the above code upon its execution will be ->
19 4 6 -3 |
Note4: Array[8] is an position which is outside the defined range of array(since array is defined for 8 elements of int type having position 0 to 7). Hence array[8]={some value} will not be reflected in array.
Get Answers For Free
Most questions answered within 1 hours.