Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ function as param

int do_sth(int a, int b, function<int(int, int)> binop) { // C++ - Like
    return binop(a, b);
}
Comment

c++ function as paramter

// function ask for void function with int param
void func ( void (*f)(int) );

// void function with int param :)
void print ( int x ) {
  printf("%d
", x);
}

// pass print function to func 
func( print )
Comment

take a function as an argument in c++

// C++ program to pass function as a
// pointer to any function
  
#include <iostream>
using namespace std;
  
// Function that add two numbers
int add(int x, int y)
{
    return x + y;
}
  
// Function that multiplies two
// numbers
int multiply(int x, int y)
{
    return x * y;
}
  
// Function that takes a pointer
// to a function
int invoke(int x, int y,
           int (*func)(int, int))
{
    return func(x, y);
}
  
// Driver Code
int main()
{
    // Pass pointers to add & multiply
    // function as required
    cout << "Addition of 20 and 10 is ";
    cout << invoke(20, 10, &add)
         << '
';
  
    cout << "Multiplication of 20"
         << " and 10 is ";
    cout << invoke(20, 10, &multiply)
         << '
';
  
    return 0;
}
Comment

C++ Function with Parameters

// program to print a text

#include <iostream>
using namespace std;
// display a number
void displayNum(int n1, float n2) {
    cout << "The int number is " << n1;
    cout << "The double number is " << n2;
}
int main() {
     
     int num1 = 5;
     double num2 = 5.5;

    // calling the function
    displayNum(num1, num2);

    return 0;
}
Comment

c++ variable arguments function

template<class... Args>
void print(Args... args)      {(cout << ... << args ) <<endl;}
Comment

c++ variable arguments function

template <typename T>
void db(T t)
{
    cout << t <<" ";
}

template<typename T, typename... Args>
void db(T t, Args... args)      {  cout << t <<" ";db(args...); }
int main() {
     db(1,"a",20,"Hey);
}
Comment

c++ function parameters

void myFunction(string fname) {
  cout << fname << " Refsnes
";
}

int main() {
  myFunction("Liam");
  myFunction("Jenny");
  myFunction("Anja");
  return 0;
}
Comment

C++ Function with Parameters

// program to print a text

#include <iostream>
using namespace std;
// display a number
void displayNum(int n1, float n2) {
    cout << "The int number is " << n1;
    cout << "The double number is " << n2;
}
int main() {
     
     int num1 = 5;
     double num2 = 5.5;

    // calling the function
    displayNum(num1, num2);

    return 0;
}
Comment

C++ Function Parameters

void myFunction(string fname) {
  cout << fname << " Refsnes
";
}

int main() {
  myFunction("Liam");
  myFunction("Jenny");
  myFunction("Anja");
  return 0;
}

// Liam Refsnes
// Jenny Refsnes
// Anja Refsnes
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ multi-dimensional arrays 
Cpp :: c++ & operator 
Cpp :: type casting in cpp 
Cpp :: c++ vector remove element by value 
Cpp :: c++ set element at index 
Cpp :: conditions in c++ 
Cpp :: modify value in map c++ 
Cpp :: cpp tutorial 
Cpp :: c++ new operator 
Cpp :: how to make sound in c++ 
Cpp :: Come concatenare stringhe in c++ 
Cpp :: set elements to 42 back 
Cpp :: english to french typing online 
C :: c colour text 
C :: wireshark tls client hello filter 
C :: pygame detect click 
C :: find maximum number between 3 numbers in c 
C :: printf with bool 
C :: get chunks of a mp4 in ffmpeg 
C :: C program to count number of digits in a number 
C :: two bytes to int c 
C :: how to ban websites on mac 
C :: reverse of a string in c 
C :: scanf string in c 
C :: pthread c 
C :: directory folders structure show windows 10 command prompt 
C :: make a function makefile 
C :: vowel and consonant C 
C :: simple calculator, using switch statement in C 
C :: c in to str 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =