void Type

The void data type always represents an empty set of values. The only object that can be declared with the type specifier void is a pointer.

When a function does not return a value, you should use void as the type specifier in the function definition and declaration. An argument list for a function taking no arguments is void.

You cannot declare a variable of type void, but you can explicitly convert any expression to type void. The resulting expression can only be used as one of the following:

Example of void Type

In the following example, the function find_max is declared as having type void.

Note:
C The use of the sizeof operator in the line find_max(numbers, (sizeof(numbers) / sizeof(numbers[0]))); is a standard method of determining the number of elements in an array.
   /**
   ** Example of void type
   **/
   #include <stdio.h>
 
   /* declaration of function find_max */
   extern void find_max(int x[ ], int j);
 
   int main(void)
   {
      static int numbers[ ] = { 99, 54, -102, 89};
 
      find_max(numbers, (sizeof(numbers) / sizeof(numbers[0])));
 
      return(0);
   }
 
   void find_max(int x[ ], int j)
   { /* begin definition of function find_max */
      int i, temp = x[0];
 
      for (i = 1; i < j; i++)
      {
          if (x[i] > temp)
             temp = x[i];
      }
      printf("max number = %d\n", temp);
   } /* end definition of function find_max  */

Related References

IBM Copyright 2003