Chapter 9

1: What storage scheme would you use for the following situations?
  1. homer is a formal argument (parameter) to a function.

  2. The secret variable is to be shared by two files.

  3. The topsecret variable is to be shared by the functions in one file but hidden from other files.

  4. beencalled keeps track of how many times the function containing it has been called.

A1:
  1. homer is automatically an automatic variable.

  2. secret should be defined as an external variable in one file and declared using extern in the second file.

  3. topsecret could be defined as a static variable with internal linkage by prefacing the external definition with the keyword static. Or it could be defined in an unnamed namespace.

  4. beencalled should be defined as a local static variable by ...

Get C++ Primer Plus, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.