How to analyse the precedence in following situation .
for (i=0; i<20; i++)
{
*array_p++ = i*i;
printf(\"%d\\n\",*arr++);
}
how
In the first sample code snippet,
for (i=0; i<20; i++)
{
*array_p++ = i*i;
printf("%d\n",*arr++);
}
array_ptr is incremented first i.e address, and then the value computed from i*i is assigned to *array_ptr since evaluation takes in the order of right to left i.e *(array_ptr ++).
In the second sample of code snippet,
for (int i=0; i<20; i++)
{
*arr = i*i;
printf("%d\n",*arr);
arr++;
printf("%d\n",(int )arr);
}
value computed from i*i is first computed and assigned to *arr, then pointer pointing to arr is incremented.
Hence there is difference in values among the 2 code snippets.