C Void Functions

In C programming, a void function is a function that does not return any value. Instead of returning a specific value like int, float, or char, a void function has a return type of void.

Syntax:


void function_name(parameters) {
    // body of the function
    // statements (code to perform task)
}

Explanation:

1. void: The return type, indicating the function does not return any value.

2. function_name: The name used to call the function.

3. parameters: Optional input values (variables) for the function to use.

Example:


#include <stdio.h>

// Void Function Definition
void welcomeMessage() {
    printf("Hello,techfliez.com!");  // Prints a message
}

// Main function
int main() {
    // Calling the welcomeMessage function
    welcomeMessage();  

    return 0;
}

Output:

Hello,techfliez.com!

Note:

  1. A void function doesn’t return anything, so there is no need for a return statement that sends a value back.

C Void Functions – Interview Questions

Q 1: What is a void function in C?
Ans: A function that does not return any value.
Q 2: How do you declare a void function?
Ans: Using the void keyword as the return type.
Q 3: Can a void function use return?
Ans: Yes, but without returning a value.
Q 4: When should we use void functions?
Ans: When a function performs an action but does not need to return data.
Q 5: Can a void function accept arguments?
Ans: Yes, void functions can accept parameters.

C Void Functions – Objective Questions (MCQs)

Q1. What is a void function in C?






Q2. Which of the following is a correct void function declaration?






Q3. What is the return type of a void function?






Q4. Can a void function have arguments?






Q5. Which statement is correct about calling a void function?






Related C Void Functions Topics