Share this page

# void

Used in function declarations to indicate that the function returns an empty or NULL value. This keyword is useful for creating functions that either do not require any parameters or do not return a value.

## Examples

### Example 1

The following example illustrates a function, send_message, that returns void. Note that unlike the Actions function, send_message does not return a value, and does not contain an expression in its return statement.

        char * example_message = "Call to database succeeded";
        send_message(example_message, 0);
        void send_message (char * msg, int msg_level) {

    // Notification message level
        if (msg_level == 0)
            lr_output_message (msg);

    // Error message level
        else if (msg_level == 1)
            lr_error_message (msg);

    // Send_message function does not return a value
             return;
            }

    Example: Output:
    Action.c(13): Call to database succeeded

### Example 2

The following example illustrates two functions, Actions and generate_random_number, which have no formal parameters. generate_random_number returns a number between 0 and 10.

The keyword void is placed between the function's parentheses to indicate they have no formal parameters.

    // No parameters sent to this function

        int x = generate_random_number();
        lr_output_message ("A number between 0 and 10: %d", x);

        // This function generates a random number between 0 and 10

        int generate_random_number(void) {
    	srand(time(NULL)); // Seed the generator
           return (rand() % 10);
        }

    Example: Output:
    Action.c(4): A number between 0 and 10: 2

Tips to improve your search results... VuGen Function Reference Version 26.1-26.3 Function Reference 26.1-26.3 All View Local Help Center View Online Help Center Version: