Home > Articles

This chapter is from the book

Workshop

Now that you’ve learned about some of the pieces of a C++ program, you can answer a couple of questions and complete a couple of exercises to firm up your knowledge.

Quiz

  1. What data type does the main function return?

    1. void

    2. int

    3. It does not return a type.

  2. What do the braces do in a C++ program?

    1. Indicate the start and end of a function

    2. Indicate the start and end of a program

    3. Straighten the program’s teeth

  3. What is not part of a function’s signature?

    1. Its name

    2. Its arguments

    3. Its return type

    Answers

    1. The main function returns an int (integer).

    2. Braces mark the start and end of functions and other blocks of code you learn about in upcoming hours.

    3. A function signature consists of its name, parameters, and the precise order of those parameters. It does not include its return type.

Activities

  • Rewrite the Motto program to display the Aarhus University motto in a function.

  • Rewrite the Calculator program to add a third integer called z in the add() function and call this function with two sets of three numbers.

To see solutions to these activities, visit this book’s website at http://cplusplus.cadenhead.org.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.