Create and Use Function with Parameters in C:
(1) FUNCTION in C language is already explained in the blog “How to create and use Function in C Language”. In this blog, we will see how to pass parameters in the function to get results.
(2) You can add as many parameters as you want.
(3) Sample C language code and its output, as shown. In this example, we created a Function with one parameter.
#include <stdio.h> #include <conio.h> // Creation of new function with parameter void myfirstfunction(int x) { switch(x) { case 1: printf(“LOW”); break; case 2: printf(“Medium”); break; case 3: printf(“High”); break; } } int main() { int x; x = 3; myfirstfunction(x); //call the function by passing x parameter getch(); return 0; } |

(4) After that go to the “Build” menu and select the “Build” option for publishing the code as shown.

(5) After building the code, press the “Run” button, as shown.

(6) After building the code, press the “Run” button, as shown.

(7) Syntax:
- Function with one parameter: MyFirstFunction(int x)
- Function with more than one parameter: MyFirstFunction(int x,char a)