What is void type how can we use it?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sivakoti
    New Member
    • Aug 2010
    • 4

    #1

    What is void type how can we use it?

    What is void type how can we use it?
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    Are you asking about C or C++?

    Off hand, I can think of four ways the void keyword is used in C:
    1. In a function prototype and function definition, this keyword is used to indicate that the function does not have a return value.
    2. In a function prototype and function definition, this keyword is used to indicate that the function does not have any arguments.
    3. Pointer-to-void is used to define/declare a generic pointer that is large enough to hold any pointer value.
    4. 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.

    Code:
    #1:
    void func1(int);
    
    #2:
    int func2(void);
    
    #3:
    void *p;
    
    #4:
    (void) printf("hello world\n");
    C++ would have all these, plus perhaps some additional usages that I don't know about.

    Comment

    Working...