Can anyone explain the logic how to add a
and b
?
#include
int main()
{
int a=30000, b=20, sum;
char *p;
p[b]
is the b-th element of the array p
. It's like writing *(p + b)
.
Now, when adding &
it'll be like writing: p + b * sizeof(char)
which is p + b
.
Now, you'll have (int)((char *) a + b)
which is.. a + b
.
But.. when you still have +
in your keyboard, use it.
As @gerijeshchauhan clarified in the comments, *
and &
are inverse operations, they cancel each other. So &*(p + b)
is p + b
.