zoukankan      html  css  js  c++  java
  • [YTU]_2570 指针练习——变量交换

    Description

    指针的功能多种多样,指针是c语言的灵魂,所以说掌握指针是很重要的。

    下面要求你用指针实现两个数字的交换

    Input

    两个int型的变量

    Output

    交换后的两个变量

    Sample Input

    1 2
    

    Sample Output

    2 1
    #include<iostream>
    using namespace std;
    int main()
    {
        int a,b;
        int *c=&a,*d=&b;
        void exc(int*,int*);
        cin>>a>>b;
        exc(c,d);
        cout<<a<<" "<<b<<endl;
        return 0;
    }
    void exc(int *c1,int *d1)
    {
        int p;
        p=*c1;
        *c1=*d1;
        *d1=p;
    }

  • 相关阅读:
    顺序容器
    forward_list
    array
    第十一章 关联容器
    C++数组
    C++标准库算法
    第十章 泛型算法
    第九章 顺序容器
    操作系统概述
    文件输入输出
  • 原文地址:https://www.cnblogs.com/sxy201658506207/p/7586396.html
Copyright © 2011-2022 走看看