In 5-2-2 C, printf calculates the parameter from right to left.
# Include <stdio. h> int main (INT argc, char ** argv) {int B = 3; int arr [] = {6, 7, 8, 9, 10}; int * PTR = arr; // * (PTR ++) + = 123; // printf ("% d, % d \ n", * PTR, * (++ PTR )); printf ("% d, % d \ n", * PTR, * (PTR ++); Return 0;}/* ----- end of main () ----- */output 7, 6
The sequence of * (PTR ++) Execution: I initially thought that because parentheses are given priority, we should first execute auto-increment in parentheses and then take values.
It can actually be: first take the value of the array element pointed to by PTR, and then add itself. And remove the brackets (* PTR ++). The results are identical.
# Include <stdio. h> int main (INT argc, char ** argv) {int B = 3; int arr [] = {6, 7, 8, 9, 10}; int * PTR = arr; * (PTR ++) + = 123; printf ("% d, % d \ n", * PTR, * (++ PTR )); // printf ("% d, % d \ n", * PTR, * PTR ++); Return 0;}/* ----- end of main () ----- */Output 8
Array arr [] = {, 7, 10} after the program runs }.
5-2-2 printf parameters from right to left