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:
12345678910111213// 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!
Дякуємо за ваш відгук!
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Запитайте мені питання про цей предмет
Сумаризуйте цей розділ
Покажіть реальні приклади
Awesome!
Completion rate improved to 2.94
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:
12345678910111213// 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!
Дякуємо за ваш відгук!