BCA SCHOOL
Programming Tutorials • Notes • Practical • Books
LATEST TUTORIALS

4 Types of User-Defined Functions in C: Arguments & Return Values | Unit 3 | BKNMU BCA

by BCA School



BKNMU Junagadh  |  BCA Sem 1  |  Unit 3

4 Types of User-Defined Functions in C Programming

Complete Classification based on Arguments Passed and Values Returned with Syntax & Code Examples

BKNMU Junagadh BCA Sem 1 Unit 3 Function Categories Arguments & Return UDF Classification
In simple words: In C programming, depending on whether a function takes input data from the calling function and whether it sends back an output result, User-Defined Functions (UDFs) are classified into 4 distinct categories. Understanding these 4 types is essential for structuring modular code and is a frequent long-question topic in BKNMU BCA Semester 1 (Unit 3) exams.
📖 The 4 Core Categories of User-Defined Functions

Based on the presence or absence of arguments and return values, functions are divided into:

Type 1: No Arg, No Return

1. Independent Routine

Takes no input from caller and returns nothing. Input, processing, and output display all happen entirely inside the function.

Type 2: With Arg, No Return

2. One-Way Input

Receives data parameters from caller, performs calculations, and prints results directly without sending values back.

Type 3: No Arg, With Return

3. Producer Routine

Receives no data from caller, collects user input or generates data internally, and sends computed output back to caller.

Type 4: With Arg, With Return

4. Complete Two-Way

Receives input arguments, executes logic independently, and returns computed result back to caller for further operations.

1️⃣ Master Table: 4 Types Comparison & Prototypes

A complete side-by-side structural comparison of prototypes, data flow, and calling styles:

Category Type Prototype Pattern Data Flow & Calling Syntax
Type 1: No Arg, No Return void sum(void); No data transfer. Invoked simply as sum();. Function handles both input and output.
Type 2: With Arg, No Return void sum(int, int); One-way data transfer into function. Invoked as sum(x, y);. Results printed inside.
Type 3: No Arg, With Return int sum(void); One-way data transfer back to caller. Invoked as res = sum();. Input taken inside.
Type 4: With Arg, With Return int sum(int, int); Two-way data transfer. Invoked as res = sum(x, y);. Pure modular computing block.
ℹ️ Key Architectural Principles:
  • void Keyword: When used as return type, it means the function returns no value. When used in parameter list (void), it signifies no incoming arguments.
  • Reusability Best Practice: Type 4 (With Arguments and Return Value) is considered the most modular and industry-standard approach because the function remains completely independent of I/O operations (scanf/printf).
💻 Practical Code Examples: All 4 Types Implemented

Type 1: Function with No Arguments and No Return Value:

#include <stdio.h>

// Declaration
void add_Type1(void);

int main() {
    add_Type1(); // Call without arguments
    return 0;
}

void add_Type1(void) {
    int a = 10, b = 20;
    printf("Type 1 Sum: %d\n", a + b);
}

Type 2: Function with Arguments and No Return Value:

#include <stdio.h>

// Declaration
void add_Type2(int a, int b);

int main() {
    int x = 15, y = 25;
    add_Type2(x, y); // Passes actual arguments x and y
    return 0;
}

void add_Type2(int a, int b) {
    printf("Type 2 Sum: %d\n", a + b);
}

Type 3: Function with No Arguments and With Return Value:

#include <stdio.h>

// Declaration
int add_Type3(void);

int main() {
    int result;
    result = add_Type3(); // Receives returned integer
    printf("Type 3 Sum received in main(): %d\n", result);
    return 0;
}

int add_Type3(void) {
    int a = 30, b = 40;
    return (a + b); // Returns calculation result
}

Type 4: Function with Arguments and With Return Value:

#include <stdio.h>

// Declaration
int add_Type4(int a, int b);

int main() {
    int num1 = 50, num2 = 50;
    int total;
    total = add_Type4(num1, num2); // Two-way communication
    printf("Type 4 Total calculated: %d\n", total);
    return 0;
}

int add_Type4(int a, int b) {
    return (a + b);
}
🔄 Step-by-Step Flow: Decision Matrix for Function Types
1

Step 1: Check Input Dependency

Does the sub-routine require external variables from main()? If YES, choose a function with arguments.

2

Step 2: Check Output Dependency

Does the caller need the calculated result for further operations? If YES, declare a function with return value.

3

Step 3: Select Appropriate Category

Combine your findings to implement Type 1, Type 2, Type 3, or Type 4 according to program design requirements.

💡 University Exam Scoring Tip: When asked about "Types of Functions" in BKNMU exams, always draw the data flow diagram for all 4 types and provide a short, identical mathematical operation (such as adding two numbers) across each type to clearly highlight structural differences.
⚠️ Common Mistake: Ignoring Return Type: If a function is declared with a return type (e.g. int) but lacks a return statement, the compiler returns an unpredictable garbage value to the caller. Always pair non-void functions with an explicit return.
📝 Quick Revision — Key Exam Points
  • 4 Categories: (1) No Arg, No Return, (2) With Arg, No Return, (3) No Arg, With Return, (4) With Arg, With Return.
  • No Arg, No Return: Self-contained; performs input, computation, and display internally.
  • With Arg, No Return: Caller supplies inputs; function displays output directly.
  • No Arg, With Return: Function produces output and delivers it back to caller.
  • With Arg, With Return: Full modularity; takes inputs from caller and returns result.