Add parameters to Function - C Function

C examples for Function:Function Definition

Introduction

The following code defines a function with two parameter.

void sum(int a, int b) {
  int sum = a + b;
  printf("%d", sum);
}

In this example, the function accepts two integer arguments and displays their sum.

Demo Code

#include <stdio.h>
void sum(int a, int b) {
  int sum = a + b;
  printf("%d", sum);
}


int main(void) {

  sum(2, 3); /* "5" */
}

Result

Void Parameter

To ensure that no arguments are passed to a parameterless function, include void in the parameter list.

/* Accepts no arguments */
void foo(void) {}

/* Accepts an unknown number of arguments */
void bar() {}

Related Tutorials