Topical Information

Here are a few questions to help you clarify your understanding of the main program.

Question Set Information

Questions

  1. Before you can use items supplied in one of the standard libraries, what must you do? (Hint: There are two things to do; although one need only be done once for a whole group of libraries.)

    
            #include every library that you wish to use.
    
            Place a using directive for the std namespace after the
            #includes and before you use any library identifiers:
            
                using namespace std;
    
    
  2. At what part of your source code will the program begin execution?

    
            The first statement after main's open curly brace:
    
                int main(void)
                {
                 -->
    
    
  3. We avoid using the int data type for our own variables, constants, etc. So why is it okay for main to return an int? (Hint: To whom does main return this int?)

    
            It's okay for main to return an int because it goes back
            to the operating system (OS).  The OS, after all, makes the final
            decision as to what size int will be:  16 or 32 bits.  Since the
            OS makes this call, the int main returns will always be
            the right size.
    
            It also doesn't hurt that we almost never need to return values
            other than 0.  Most of the time our return value is in the
            range [0..255].
    
    
  4. Variable declarations should go inside the (curly) braces of the main program.
  5. What does having a void (or just plain nothing) inside main's parentheses signify?

    
            It says that the main function doesn't require any inputs
            (arguments) before beginning execution.  (It may, of course, begin
            execution by requesting inputs from the user via a cout/cin
            combination...*shrug*)
    
    
  6. What statement ends (almost) all mains?

    
            return 0;
    
    

    What is the meaning of that 0? (And, yes, the 0 you just mentioned DOES have significance!)

    
            The 0 represents that we experienced no errors
            while executing.  No problems.  No trouble.  No issues.