C Function Arguments and Return Value

A function can take values (arguments) and can give a value back (return value). Based on this there are four types of functions.

TypeArgumentsReturn value
1NoNo
2YesNo
3NoYes
4YesYes
#include <stdio.h>

void hello(void) {                 // no argument, no return
    printf("Hello\n");
}

void showSquare(int n) {           // argument, no return
    printf("Square = %d\n", n * n);
}

int readFive(void) {               // no argument, return
    return 5;
}

int multiply(int a, int b) {       // argument and return
    return a * b;
}

int main(void) {
    hello();
    showSquare(4);
    printf("%d\n", readFive());
    printf("%d\n", multiply(6, 7));
    return 0;
}

Output:

Output of the above program is

Hello
Square = 16
5
42

Terms to know

  • Parameters are the variables in the function definition (int a, int b).
  • Arguments are the real values you pass when calling (multiply(6, 7)).
  • A function can return only one value with return. To get more values you can use pointers or a structure.
  • After return executes, the function ends at once.
Note: C does not have default arguments or function overloading. Each function needs a different name.

Next: C Call by Value and Call by Reference.


Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments
Write a C program to find the factorial of a number using recursion
Write a C program to swap two numbers using a function and pointers
Interview Questions & Answers
What is the difference between call by value and call by reference in C?
What is recursion in C?
What is the difference between local and global variables in C?
What are storage classes in C?
What is the use of the static keyword in C?