What is void in C?

C Programming Language >   Overview of C Language >   First Program in C Hello World  

Short Question

1185


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.


This Particular section is dedicated to Question & Answer only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.




Join Our telegram group to ask Questions

Click below button to join our groups.