首页 > 其他分享 >Function pointer array

Function pointer array

时间:2022-09-07 23:34:20浏览次数:79  
标签:Function product const pFunc double argv array pointer

#include <iostream>

using namespace std;

double sum(const double, const double);
double product(const double, const double);
double subtract(const double, const double);
double (*pFunc[])(const double, const double) { sum, product, subtract };


int main(int args, char** argv)
{
    double a = atol(argv[1]), b = atol(argv[2]);
    double result = pFunc[0](a, b);
    cout << fixed << "Sum=" << result << endl;
    result = pFunc[1](a, b);
    cout << "Product=" << fixed << result << endl;
    result = pFunc[2](a, b);
    cout << "Subtract=" << fixed << result << endl;
}

double subtract(const double a, const double b)
{
    return a - b;
}

double product(const double a, const double b)
{
    return a * b;
}

double sum(const double a, const double b)
{
    return a + b;
}

 

 

标签:Function,product,const,pFunc,double,argv,array,pointer
From: https://www.cnblogs.com/Fred1987/p/16667710.html

相关文章

  • ArrayList 为什么线程不安全【转载】
    一、源码分析首先看看这个类所拥有的部分属性字段:1publicclassArrayList<E>extendsAbstractList<E>2implementsList<E>,RandomAccess,Cloneable,java.io.......
  • How to use a std::function as a C style callback
    HowcanIuseastd::functioninafunctionwhichexpectsaC-stylecallback?Ifthisisnotpossible,whatisthenextbestthing?Example://---someCcode......
  • FormArray 调整数据位置
    getbeans(){returnthis.validateForm.get('beans')asFormArray;}change(fromIdx,toIdx){constformGroup=this.beans.at(fromIdx);this.beans.......
  • array.js 说明
    文件说明:数组操作集合引入代码:import$arrayfrom'@/common/js/array.js'varlists=['桌子','椅子','电视','空调','冰箱']//从数组中随机抽取二个元素varg......
  • Java 中的二维数组(2d array):一些细节
    二维数组长度char[][]paul=newchar[2][5];intn1=paul[1].length;System.out.println(n1);//5intn2=pa......
  • 16.判断JSON是JSONObject或者JSONArray
    JSONObjectjson=newJSONObject();Objectjson1=newJSONTokener(rrinfo.getParametersJson()).nextValue();if(json1instanceofJSONObject){json=JSONObject.parse......
  • 任务(task)和函数(function)
     task和function说明语句分别用来定义任务和函数。利用任务和函数可以把一个很大的程序模块分解成许多较小的任务和函数便于理解和调试。输入、输出和总线信号的值可以......
  • [Google] LeetCode 2172 Maximum AND Sum of Array 状态压缩DP
    YouaregivenanintegerarraynumsoflengthnandanintegernumSlotssuchthat2*numSlots>=n.TherearenumSlotsslotsnumberedfrom1tonumSlots.You......
  • [Go] Pointer
    varnamestring varnamePointer*string//Pointer name="Beyonce" namePointer=&name//AssignaPointer fmt.Println("Name:",name) fmt.Println("Nam......
  • ArrayBuffer、Float32Array、Uint8Array 详解
    ArrayBufferArrayBuffer()是一个普通的JavaScript构造函数,可用于在内存中分配特定数量的字节空间。constbuf=newArrayBuffer(16);//在内存中分配16字节alert(......