About the combination of value operator *, and () and self-increment

Regarding the combination of the value operator "*", and () and self-increment,
the following content is only my personal understanding

#include <stdio.h> 
int main() 
{
    
       
int x[] = {
    
    10, 20, 30};     
int *px = x; 
printf("%d,", ++*px); //优先级相同,自右向左,先取值10,再自增,答案11  
printf("%d,", *px);    
px = x; //每次将指针指向的首地址重置
printf("%d,", (*px)++);//取值11,自增运算符在右侧,输出值不变,实际值+1 
printf("%d,", *px);   
px = x; 
printf("%d,", *px++);    //*px++ == *(px++)(优先级相同,自右向左),相当于*x, x=px++,由于自增运算符在右侧,所以x等于px*,*x==*px==12,但实际上现在的px已经自增到后一个单位,首地址改变
printf("%d,", *px);    //所以此时的*px就是后一个单位的值
px = x; 
printf("%d,", *(px++));    //先自增,但是运算符在右侧,自增在此不体现,但实际已经向右移一个单位,首地址改变
printf("%d,", *px);     //实际移了一个单位
px = x;
printf("%d,", *++px);    //先自增,自增运算符在左,自增效果体现
printf("%d\n", *px);  
return 0;
} 

It is mainly necessary to pay attention to the position of the self-increment operator, and to understand the precedence and associativity of the operator

Guess you like

Origin blog.csdn.net/jiuchena/article/details/103377444