指针传递

#include <bits/stdc++.h>
using namespace std;
/* 要接收相应变量的内存中变量的值,需要利用指针, 
   在接收内存地址的相应变量位置变量前加“*”号,
   运算是同样需要带*号,表示指针所指的那个变量参与运算*/ 
int DSWEASDFCSF ( int *a  , int b)
{
    int n = *a + b ;
    *a = *a + 1 ;
    return n;
}
int main()
{
    int x,c=3,d=5;
    //调用DSWEASDFCSF函数,要传递c的内存地址,前面加&号 
    x = DSWEASDFCSF(&c,d);
    cout<<x<<" "<<c;
    return 0;
}

 

posted @ 2023-10-29 09:25  hanxuyao  阅读(10)  评论(0)    收藏  举报