Tuesday, November 5, 2019
Definition of Void in C and C
Definition of Void in C and C          In computer programming, whenà  voidà  is used as a function return type, it indicates that the function does not return a value. When void appears in a pointer declaration, it specifies that the pointer is universal. When used in a functions parameter list, void indicates that the function takes no parameters.à            Void as a Function Return Type      Void functions, also called nonvalue-returning functions, are used just like value-returning functions except void return types do not return a value when the function is executed. The void function accomplishes its task and then returns control to the caller. The void function call is a stand-alone statement.à           For example, a function that prints a message doesnt return a value. The code in C takes the form:         void printmessage ( )         {         à  cout  Im a function that prints a message!;         }         int main ( )         {         à  printmessage ( );         }         A voidà  function uses a heading that names the function followed by a pair of parentheses. The name is preceded by the word void, which is the type.          Void as a Function Parameter      The void can also appear in the parameter list part of the code to indicate the function takes no actual parameters. C can take the empty parentheses, but C requires the word void in this usage.à  In C, the code takes the form:         voidà  printmessageà  (void )         {         à  cout à  Im a function that prints a message!;         Note that the parentheses that follow the function name are not optional in any case.          Voidà  as a Pointer Declaration      The third use of void is a pointer declaration that equates to aà  pointer to something left unspecified, which is useful to programmers who write functions that store or pass pointers withoutà  using them. Eventually, it must be cast to another pointer before it is dereferenced. A void pointer points to objects of any data type.    
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.