Зміст курсу
C++ Intermediate | Mobile-Friendly
C++ Intermediate | Mobile-Friendly
Parameters
Let’s imagine we have 3 pets: dog, cat, and pig. They all make different sounds, and it would be silly to write 3 different functions with the same functionality (outputting words). Here we can use parameters! Parameters (or arguments) act like variables inside the function and are specified with their type inside the parentheses after the function. You can use as many arguments as you want:
Code:
// Function declaration void myFunc(string animal, string sound) { cout << animal << " says " << sound << endl; } int main() { // Call the function to be executed myFunc("cat", "meow"); myFunc("dog", "bow"); myFunc("pig", "wee"); return 0; }
Variables you use can be any type, and your function can also accept different types simultaneously!
Дякуємо за ваш відгук!