+ 1

can anyone explain this code

following is the code for addition of two numbers without using arithematic operators.. main() { int x,y,result; x=2; y=5; char *p=0; result=(int)&((&(p[x]))[y]); printf("sum=%d",result);

14th Aug 2017, 4:54 AM
Devaki:)
Devaki:) - avatar
1 Answer
+ 2
p==0 p[x] == *(p+x) so &(p[x]) == p+x == x x[y] == *(x+y) so &(x[y]) == x+y (which was cast as a pointer) x+y is then cast as an int, which is 7 and then displayed
14th Aug 2017, 5:21 AM
Baptiste E. Prunier
Baptiste E. Prunier - avatar