Monday, March 2, 2020

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.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.