What is void type how can we use it?
What is void type how can we use it?
Collapse
X
-
Are you asking about C or C++?
Off hand, I can think of four ways the void keyword is used in C:- In a function prototype and function definition, this keyword is used to indicate that the function does not have a return value.
- In a function prototype and function definition, this keyword is used to indicate that the function does not have any arguments.
- Pointer-to-void is used to define/declare a generic pointer that is large enough to hold any pointer value.
- A function call can be cast to void as a sort of comment that you know the function has a return value but that you are deliberately ignoring it.
C++ would have all these, plus perhaps some additional usages that I don't know about.Code:#1: void func1(int); #2: int func2(void); #3: void *p; #4: (void) printf("hello world\n");
Comment