Pointer practice (1)

First of all, the "&" and "*" operators will be explained again:
Example:

The premise pointer_1=&a
(*pointer_1)++ is equivalent to a++.
Note that parentheses are necessary. If there are no parentheses, it becomes

*pointer_1++, where ++ and ✳ are the same priority, and the direction is from right to left, so it is equivalent to

*(pointer_1++)

Simple pointer application:
input two integers, a and b, and output a and b in the order of first big and then small.
Code example:

#include<stdio.h>
void fun(int *p,int *l);
int main()
{
    
    
	int *p,*m,a,b;
    printf("请输入两个整数:\n");
	scanf("%d%d",&a,&b);
	p=&a;
	m=&b;
	if(a<b)
	{
    
    
	fun(p,m);
	}
	printf("\n%d,%d\n",a,b);

}
void fun(int *p,int *l)
{
    
    
	int ben;
	printf("我在交换中.....");
	

		ben=*p;
		*p=*l;
		*l=ben;
	
}

Familiar with the operators & and ✳ for the purpose of this code

One mistake is
that you
cannot write if (p>l) when you are doing comparisons, and you
must add the value symbol if (*p>*l).

Guess you like

Origin blog.csdn.net/yooppa/article/details/112647998