9.4 Functions without Inputs and Outputs


9.4 Functions without Inputs and Outputs

Functions can be designed to simply perform a process. These functions return nothing and/or receive no arguments. Since void is a keyword used to designate something that is data type-less or undefined, it is used as the return type for functions that do not return a value. Furthermore, functions that do not return a value do not need to use the return keyword. If such a function wishes to end prematurely, it can do so using the return keyword without a data type, as in return;. Consider the following code:

      #include <iostream>      void SayHello(int NumberOfTimes)      {         for(int counter = 0; counter < NumberOfTimes; counter++)         {           std::cout<<"hello world ";         }      }      void SayBye()      {         std::cout<<"\nbye\n";         return;      }      int main()      {         for(int counter = 0; counter < 10; counter++)         {           SayHello(5);         }         for(int counter = 0; counter < 10; counter++)         {           SayBye();         }      return 0; } 




Introduction to Game Programming with C++
Introduction to Game Programming with C++ (Wordware Game Developers Library)
ISBN: 1598220322
EAN: 2147483647
Year: 2007
Pages: 225
Authors: Alan Thorn

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net