This article is a mirror article of machine translation, please click here to jump to the original article.

View: 15359|Reply: 2

[C] How to reference pointer variables and compare sizes

[Copy link]
Posted on 12/10/2015 1:29:45 PM | | | |
Input two integers, A and B, and output A and B in the order of first largest and then smallest.
The code is as follows:
How to reference a variable address & take address operator *Pointer operator (or indirect access operator)
#include "stdafx.h"
#include <stdio.h>
int main(int argc, char* argv[])
{
    int *p1,*p2,*p,a,b;
    printf("please enter two integer numbers:");
    scanf("%d,%d",&a,&b);
    p1=&a;
    p2=&b;
    if(a<b)
    {p1=&b;p2=&a;}//Pointer emphasis {p=p1; p1=p2; p2=p; Now it is directly assigned new values to P1 and P2, so that there is no need to define the intermediate variable p, and the program can become more concise
    This algorithm does not swap the values of integer variables, but the values of two pointers, (addresses of a and b)

    printf("a=%d,b=%d\n",a,b);
    printf("max=%d,min=%d\n",*p1,*p2);
    return 0;
}







Previous:C# uses GET, POST requests to get results
Next:Pointer variables as parameters of the function Compare size
Posted on 12/10/2015 1:44:03 PM |
This is for adding code
 Landlord| Posted on 12/10/2015 1:48:06 PM |
Published on 2015-12-10 13:44
This is for adding code

I do not know
  1. 原来是这个样子,
Copy code
, seems to understand a little.
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com