当前位置:网站首页>*P++, (*p) + +, * (p++) differences

*P++, (*p) + +, * (p++) differences

2022-07-05 06:47:00 like_ new_ human

First of all, understand ()* ++ Priority relationship
() The priority is highest , Next is p++ Post auto increment ,* and ++p The former auto increment priority is the same
The following code is used to illustrate the difference between the three

# include <stdio.h>
int main (void)
{
    
 int a[5] = {
    1,2,3,4,5};
 int* p = a;
 int A;
 // Now? p Point to a[0]
  A = *p++;
 printf ("*p++ = %d\n",A);
 printf ("*p = %d\n",*p);
 //A by 1 *p by 2 *p Assign first to A  One more 
  p = a;
 A = (*p)++;
 printf ("(*p)++ = %d\n",A);
 printf ("*p = %d\n",*p);
  //A by 1 *p by 2 *p Equivalent to a[0]  hold a[0] The value is assigned to A a[0] Since the increase again 1
 p = a;
 A = *(p++);
 printf ("*(p++) = %d\n",A);
 printf ("*p = %d\n",*p);
 //A by 2 *p by 2 *(p++) And *p++ Equivalent  ++ It's priority 
 return 0;
}
							**--- A cute new little broken article **
原网站

版权声明
本文为[like_ new_ human]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140600406573.html