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

View: 12614|Reply: 0

[C] Pointer variables as parameters of the function Compare size

[Copy link]
Posted on 12/10/2015 1:46:59 PM | | |
Pointer variable as a function parameter The function of the pointer type is to tell the address of one variable to another function
//在函数过程中通过指针实现交换两个变量的值
#include "stdafx.h"
#include <stdio.h>
int main(int argc, char* argv[])
{
    void swap(int *p1,int *p2);
    int a,b;
    int *pointer_1,*pointer_2;
    printf("please enter a and b");
    scanf("%d,%d",&a,&b);
    pointer_1=&a;
    pointer_2=&b;
    if(a<b) swap(pointer_1,pointer_2);
    printf("max=%d,min=%d\n",a,b); Output result
    return 0;
}
void swap(int *p1,int *p2)// The point of the pointer, pointer as a parameter When the function is called, the value of the parameter variable is transferred to the parameter variable, which is the method of value transfer.
{int temp;
temp=*p1;
*p1=*p2;           Make *p1 and *p2 interchangeable
*p2=temp;

}




Previous:How to reference pointer variables and compare sizes
Next:Use the array name as the argument of the function The reverse order of the array
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