-->

Facebook

Jasper Roberts - Blog

Thursday, September 18, 2014

Void


  • void (type)

Empty data type

When used as a function return type, void means that the function does not return a value.

void hello(char *name)
  {
    printf("Hello, %s.",name);
  }


When found in a function heading, void means the function does not take any parameters.


  • int init(void)

  {
    return 1;
                   }


  • Void pointers:

Pointers can also be declared as void.

Void pointers can't be dereferenced without explicit casting. This is because the compiler can't determine the size of the object the pointer points to.

Example:
  int x;
float r;
  void *p = &x;          /* p points to x */

int main (void)
  {
    *(int *) p = 2;
    p = &r;              /* p points to r */
    *(float *)p = 1.1;
  }

from: turbo c

No comments:

Post a Comment