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

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;
}
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 :: prime numbers less than a given number c++ 
Cpp :: sort vector using marge sorting in c++ 
Cpp :: singleton c++ 
Cpp :: sleep system function linux c++ 
Cpp :: c++ vector loop delete 
Cpp :: c++ int main() 
Cpp :: flags for g++ compiler 
Cpp :: abs in c++ 
Cpp :: vector.find() 
Cpp :: c++ init multidimensional vector 
Cpp :: find primes in a range in c++ 
Cpp :: string iterator in c++ 
Cpp :: Story of c++ 
Cpp :: how to erase a certain value from a vector in C++ 
Cpp :: c vs c++ 
Cpp :: C++ program that prints the prime numbers from 1 to 1000. 
Cpp :: OpenGL C++ Version 
Cpp :: sort index c++ 
Cpp :: c++ string to char array 
Cpp :: fast way to check if a number is prime C++ 
Cpp :: rotate array cpp 
Cpp :: c++ int to char* 
Cpp :: c++ program to print natural numbers from 1 to 10 in reverse order using while loop 
Cpp :: how to specify the number of decimal places in c++ 
Cpp :: c++ struct 
Cpp :: reverse sort a vector 
Cpp :: what is g++ and gcc 
Cpp :: c++ looping through a vector 
Cpp :: quicksort 
Cpp :: comparing characters of a string in c++ 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =