I got this function from my teacher today :
int nums[] = { 9, 5, 4, 2, 8, 1, 3, };
int *p = nums;
int tmp_num = *(p + 2);
p = &nums[0];
*p = *p + *(p + 1);
++p;
++(*p);
*(p + 2) = 7;
p = &nums[5] + 1;
*p = 4;
int size = sizeof nums / sizeof nums[0];
for (int i = 0; i < size; ++i)
{
cout << "nums[" << i << "] : " << nums[i] << endl;
}
The result :
nums[0] : 14
nums[1] : 6
nums[2] : 4
nums[3] : 7
nums[4] : 8
nums[5] : 1
nums[6] : 4
Can someone explain how does the function work? I really don't understand how can you get those results. Thank you!