No Return Without Argument Function in C


In C programming, a function that does not take any arguments and does not return a value is called a void function. The syntax for defining a void function is as follows:

        Syntax:
           return_type function_name ( parameter1, parameter2, ... )
           {
                 // body of Statement ;
           }

        Example :
           void function_name ( )
           {
                 // body of Statement ;
           }

  • Here, the 'void' keyword is used as the return type to indicate that the function does not return any value.
  • A void function can be called in the same way as other functions, by simply using the function name followed by empty parentheses:

            function_name ( );

Here is an example of a void function that prints a message to the console:

  • This program defines a void function called add that simply prints the message "Total of a and b" to the console. The main function calls the add function, which executes the code inside the function and prints the message.
  • Void functions are useful in C programming when you want to perform a specific task without returning any value, such as displaying a message, initializing a variable or updating a data structure

Source Code

//No Return Without Argument Function in C
/*
    1.Function Declaration
    2.Function Definition
    3.Function Calling
 
*/
#include<stdio.h>
 
//Function Declaration
void add();
 
int main()
{
    //Function Calling
    add();
    return 0;
}
//Function Definition
void add()
{
    int a,b,c;
    printf("\nEnter The Value of A & B :");
    scanf("%d%d",&a,&b);
    c=a+b;
    printf("\nTotal : %d",c);
}
 
To download raw file Click Here

Output

Enter The Value of A & B :12
34

Total : 46

List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C