• C++ 指针


    C++ 指针
    学习 C++ 的指针既简单又有趣。通过指针,可以简化一些 C++ 编程任务的执行,还有一些任务,如动态内存分配,没有指针是无法执行的。所以,想要成为一名优秀的 C++ 程序员,学习指针是很有必要的。

    正如您所知道的,每一个变量都有一个内存位置,每一个内存位置都定义了可使用连字号(&)运算符访问的地址,它表示了在内存中的一个地址。

     1 #include <iostream>
     2 
     3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
     4 using namespace std;
     5 int main(int argc, char** argv) {
     6     int max(int a,int b,int c);
     7     double max(double a,double b,double c);
     8     long max (long a,long b,long c);
     9     
    10     int i1,i2,i3,i;
    11     cin >>i1>>i2>>i3;
    12     i=max(i1,i2,i3);
    13     cout <<"i_max="<<i<<endl;
    14     
    15     double d1,d2,d3,d;
    16     cin >>d1>>d2>>d3;
    17     d=max(d1,d2,d3);
    18     cout <<"d_max="<<d<<endl;
    19     
    20     long g1,g2,g3,g;
    21     cin >>g1 >>g2>>g3;
    22     cin >>g1>>g2>>g3;
    23     g=max(g1,g2,g3);
    24     cout <<"g_max="<<g<<endl; 
    25     
    26     return 0;
    27 }
    28 
    29 int max(int a,int b,int c)
    30 {
    31     if(b>a) a=b;
    32     if(c>a) a=c;
    33     return a;
    34 }
    35 
    36 double max(double a,double b,double c)
    37 {
    38     if(b>a) a=b;
    39     if (c>a) a=c;
    40     return a;
    41 }
    42 
    43 long max(long a,long b,long c)
    44 {
    45     if(b>a)a=b;
    46     if(c>a)a=c;
    47     return a;
    48 }
  • 相关阅读:
    Eclipse 安装配置指南
    CentOS下安装Git
    MySQL5.5在Windows下的安装
    NSInvocation调用
    动态调用
    模拟静态变量及静态类继承
    respondsToSelector判断是否实现了某方法
    JAVA闭包
    IMP获取函数指针
    [链表] 对链表与文件的结合使用的一点看法
  • 原文地址:https://www.cnblogs.com/borter/p/9401064.html
Copyright © 2020-2023  润新知