Skip to study material
← Question index

QUESTION 06 · Functions

Explain the four categories of functions based on arguments and return values.

5 marks

Answer in brief

Functions are commonly classified by whether they receive arguments and whether they return a value.

No arguments and no return value

void greet(void)
{
    puts("Welcome");
}

Arguments and no return value

A function such as void show_square(int n) receives a number and displays its square. The caller supplies the input through an argument, but the function does not return a value. Displaying a result is an output action, not a returned value.

No arguments and a return value

A function such as int fixed_limit(void) can return a fixed limit without receiving arguments. It might instead obtain a value from another permitted source, but that is separate from the parameter list. The caller can store or use its returned value.

Arguments and a return value

A function such as int add(int a, int b) receives two numbers and returns their sum. This is useful when the caller should decide whether to print the result, store it or use it in another calculation.

Choosing a category

Choose the interface according to the task. Passing values as arguments makes a function easier to reuse than making every function read directly from the keyboard. Returning a calculated value often makes testing easier. A void function may still change an object through a pointer parameter or display output; void only says there is no returned value.

C program and output

/* CodeBhavya | PPS AR25 | Learning example */
#include <stdio.h>
void greet(void) { puts("Welcome"); }
void show_square(int n) { printf("Square = %d\n", n * n); }
int fixed_limit(void) { return 10; }
int add(int a, int b) { return a + b; }
int main(void)
{
    greet();
    show_square(3);
    printf("Limit = %d\n", fixed_limit());
    printf("Sum = %d\n", add(4, 6));
    return 0;
}

Sample input and output

This example uses values already written in the program.

Output

Welcome
Square = 9
Limit = 10
Sum = 10

Related exam questions

Related questions in the function categories category from the supplied papers. The marks below are the printed allocations, including any combined subquestion.

  • March/April 2023 · Q8(a) · 5 marks

    Discuss types of functions based on parameters and return type.

    Paper P02 · page 2
  • March/April 2023 · Q9(a) · 5 marks

    Explain differences between user-defined and library functions.

    Paper P02 · page 2

View this category in the exam question bank →