How to write and invoke functions that take parameters? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to write and invoke functions that take parameters?

Hi guys, I am trying to teach myself C... so I am new... and I have the following exercise to do: a. Write the first line of a function named Zoo1() that takes three parameters: an int and two char. b. Write a line of code that invokes Zoo1(), passing as arguments the value 11, the letter a, and the letter z. Somehow, I've managed to get a result, but I am not so sure I took the above mentioned steps. Can somebody please check and let me know? Link to the code: https://code.sololearn.com/ciZ5widFRKMD Thank you so much!

29th Dec 2019, 10:47 PM
snowflakenrgy
2 Answers
+ 4
This is what they want instead. #include <stdio.h> void Zoo1(int one, char two, char three) { printf("%i\n", one); printf("%c\n", two); printf("%c\n", three); } int main () { printf("Result is: \n"); Zoo1(11, 'a', 'z'); return 0; } A parameter is like a letterbox, in which you can put values *from the outside* of the function. Look at the function call in main: Into the parentheses I put the values. Now they're delivered to the function and can be used there.
29th Dec 2019, 11:02 PM
HonFu
HonFu - avatar
+ 1
Thank you so much HonFu! 🙏
29th Dec 2019, 11:04 PM
snowflakenrgy