Thursday 1 June 2017

Define void data type and write any three use of it.

Q : Define void data type and write any three use of it.

The data type void actually refers to an object that does not have a value of any type. Void is also used to indicate when a function does not return a value or no argument. Such a function is used for its side effect and not for its value. In the function declaration and definition, we have indicated that the function does not return a value by using the data type void to show an empty type, i.e. no value. Similarly, when a function has no formal parameters, the keyword void is used in the function prototype and header to signify that there is no information passed to the function.



1. When used as a function return type:
the void keyword specifies that the function does not return a value.

void show()
 {
      printf("This function has no return type");
 }



2. When used for a function's parameter list:
void specifies that the function takes no parameters.

int sum(void)
 {
      int a,b;
      printf("Enter Two number>> ");
      scanf("%d%d",&a,&b);
      return a+b;
 }

3. When used in the declaration of a pointer:
void specifies that the pointer is "universal."

void main()
{
     void *p;
     int a=10;
     char b='A';
     float c=9.19;
     p=&a;
     printf("\nPrinting Integer data %d",(*(int *)p));
     p=&b;
     printf("\nPrinting character data %c",(*(char *)p));
     p=&c;
     printf("\nPrinting float data %f",(*(float *)p));
}

No comments:

Post a Comment