What is void in C?

Short Answer
Views 1049

Answer:

  • Void is an empty data type that has no value.
  • We use void data type in functions when we don’t want to return any value to the calling function.
  • Example:

void sum (int a, int b); – This function won’t return any value to the calling function.
int sum (int a, int b); – This function will return value to the calling function.

 
 
  • We use void data type in pointer like “void *p”. It means, pointer “p” is neither pointing to int data type nor char data type. It acts as generic pointer. We are using void pointer when we are not sure on the data type that this pointer will point to. We can use void pointer to refer either integer data or char data. But, this void pointer should not be dereferenced without explicit type casting.
  • We use void in functions as “int function_name (void)”. Here void means, this function does not pass any argument.

Related Articles:

This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of C Programming Language, click the links and dive deeper into this subject.

Join Our telegram group to ask Questions

Click below button to join our groups.