What is the purpose of the keyword void in a function declaration ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ANURAGBAJPAI
    New Member
    • Nov 2008
    • 4

    What is the purpose of the keyword void in a function declaration ?

    This is a question in my text book, and the answer is-
    The keyword void in a function declaration has a significant purpose.When the return type of a function is void , that means the function doesn't return anything.Thus we can say that the purpose of specifying the return type void is that it doesn't return anything.

    Please explain the answer.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    What do you not understand about it?

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      You have to remember that a function is an instance of its return type. That is, a function that returns an int becomes an int when you call the function. The compiler knows this. Therefore, you can use the function call as an int.

      The void return says the function is not an instance of anything. In techno-speak a void return means the function cannot be used as an r-value.

      Comment

      • donbock
        Recognized Expert Top Contributor
        • Mar 2008
        • 2427

        #4
        A function prototype declares the type of the return value of a function. It also declares the number and types of the function parameters. "Void" may appear in either context. Which usage of "void" are you asking about?
        Code:
        void foo(int arg);
        int bar(void);

        Comment

        • Manikgisl
          New Member
          • Oct 2008
          • 37

          #5
          While Function Declaration u must specify the return value Or Otherwise

          it will Take as integer


          if programmer wants to be function should not Return value to calling function

          they must specify VOID keyword


          This is usage the void while function declaration

          Comment

          Working...