📦 C Function Parameters and Arguments

In C, parameters are variables defined in a function’s declaration/definition, and arguments are the actual values passed when calling the function. Parameters help you reuse functions with different inputs.

🔹 What Are Parameters & Arguments?

  • Parameter: A variable in the function definition.
  • Argument: The value passed to the function during the call.

📝 Example 1: Function with One Parameter

This function accepts a name as a parameter and prints a greeting.

#include <stdio.h>

void greet(char name[]); // Function declaration

int main() {
    greet("Charlie"); // "Charlie" is the argument
    return 0;
}

void greet(char name[]) { // 'name' is the parameter
    printf("Hello, %s!\n", name);
}
  

Try It Now

📝 Example 2: Function with Two Parameters

Pass two numbers to a function and print their sum.

#include <stdio.h>

void add(int a, int b); // Function declaration

int main() {
    add(5, 7); // Passing arguments 5 and 7
    return 0;
}

void add(int a, int b) { // Parameters 'a' and 'b'
    printf("Sum: %d\n", a + b);
}
  

Try It Now

📝 Example 3: Return Value Using Parameters

This example shows how parameters can be used to return computed values.

#include <stdio.h>

int multiply(int x, int y); // Function declaration

int main() {
    int result = multiply(3, 4);
    printf("Result: %d\n", result);
    return 0;
}

int multiply(int x, int y) { // Parameters
    return x * y;
}
  

Try It Now

🧠 Quick Tips

  • You can pass multiple arguments by separating them with commas.
  • Parameters must match the data types and order of the passed arguments.
  • Arguments are evaluated before being passed to functions.

🎯 Summary

  • Parameters = input variables in function definition.
  • Arguments = actual values passed during the function call.
  • They make functions dynamic and reusable.

⚙️ Practice Time!

Try changing the arguments, add more parameters, or use different data types. The more you experiment, the more comfortable you’ll get with reusable C functions!