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; } |
![Create and Use Function with Parameters in C Language 1 Sample C language code for function with paramater](https://erpconsultors.com/wp-content/uploads/2022/02/Sample-C-language-code-for-function-with-paramater.png)
(4) After that go to the “Build” menu and select the “Build” option for publishing the code as shown.
![Create and Use Function with Parameters in C Language 2 click on build for switch statement in codeblocks](https://erpconsultors.com/wp-content/uploads/2022/02/click-on-build-for-switch-statement-in-codeblocks.png)
(5) After building the code, press the “Run” button, as shown.
![Create and Use Function with Parameters in C Language 3 run code for function parameters in C](https://erpconsultors.com/wp-content/uploads/2022/02/run-code-for-function-parameters-in-C.png)
(6) After building the code, press the “Run” button, as shown.
![Create and Use Function with Parameters in C Language 4 Function Parameter Output in C Obtained](https://erpconsultors.com/wp-content/uploads/2022/02/Function-Parameter-Output-in-C-Obtained.png)
(7) Syntax:
- Function with one parameter: MyFirstFunction(int x)
- Function with more than one parameter: MyFirstFunction(int x,char a)