当前位置:网站首页>Comparative examples of C language pointers *p++, * (p++), * ++p, * (++p), (*p) + +, +(*p)

Comparative examples of C language pointers *p++, * (p++), * ++p, * (++p), (*p) + +, +(*p)

2022-07-06 18:06:00 The way of growth of Peng

//C Language pointer *p++、*(p++)、*++p、*(++p)、(*p)++、++(*p) Comparative examples 
#include<stdio.h>

int main(){
    
	int a[] = {
    10,20,30,40,50};
	int *p;
	p = a;
	printf("*p:%d\n",*p);// The initial position is pointing a[0] 
	printf("*p++:%d\n",*p++);// here P Or point to a[0], Output finished a[0] The post pointer address automatically adds one to point to the next position ( That is to say a[1] The location of ) 
	printf("*(p++):%d\n",*(p++));// Now point to a[1]. Output finished a[1] The post pointer address automatically adds one to point to the next position ( That is to say a[2] The location of )
	printf("*++p:%d\n",*++p);// The pointer now points to a[2] The location of . The pointer address first adds one to point to the next position ( That is to say a[3] The location of ) Then the output 
	printf("*(++p):%d\n",*(++p));// The pointer now points to a[3] The location of . The pointer address first adds one to point to the next position ( That is to say a[4] The location of ) Then the output 
	printf("(*p)++:%d\n",(*p)++);// The pointer now points to a[4] The location of . First, the output a[4] Then add one to the value of this address ( That is to say a[4] From 50 become 51). 
	printf("++(*p):%d\n",++(*p));// here a[4] The value of is already 51 了 . First pair a[4] The value of is increased by one ( That is to say a[4] From 51 become 52) Then the output . 
	return 0;
} 
/*  summary : *(p++)  and  *p++  Equivalent  *++p  and  *(++p)  Equivalent  */ 

 Output interface

原网站

版权声明
本文为[The way of growth of Peng]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060943302377.html