
Function Parameters in C
In C, function parameters are used to pass data to a function. They're like placeholders for actual values (called arguments) that you provide when calling the function. ????
? Basic Syntax
return_type (type1 param1, type2 param2);
Example:
int add(int a, #include // Function declarationvoid greetUser(char name[]);() { greetUser("Alice"); // Passing argument return 0;}// Function definitionvoid greetUser(char name[]) { void change(int x) { x = () { int num = 50; change(num); printf("%d\n", num); // Output: 50}
Use Pointers for Pass-by-reference:
void change(int *x) { *x = () { int num = 50; change(&num); printf("%d\n", num); // Output: 100}
? Multiple Parameters Example
float area(float width, float height) { return width * height;}
Call with:
float result = area(5.0, 3.5);
? Summary
Function parameters are variables listed in the function's definition.
Arguments are the actual values passed during the call.
C uses pass-by-value by default.
Use pointers to simulate pass-by-reference when needed.