Practical C++ Programming by manish baranwal

Start from the beginning
                                        

Parameter Type Summary

C++ has a lot of different ways to pass parameters. Slide 18 lists the various types. At this point lots of

examples are useful.

One question that keeps cropping up: “Aren’t reference parameters just like C pointer variables?”

Answer: There are two differences: Pointer variables can point to an array or a single variable. You can’t

tell which from inside the function. Reference parameters can only reference one variable. Secondly,

we’ve studied reference parameters, and we haven’t gotten to pointer variables yet.

Programming Techniques

There are many different programming techniques. Which one you use depends on your experience, and

Page 29

the type of problem you have to solve. This section is designed to give the students a little introduction

to various techniques.

One way of showing how the various techniques work is to design and implement a program line.

Explain how you are analyzing the problem, designing the code, and implementing the solution.

Recursion

Emphasize the two rules of recursion. There are lots of problems that are normally solved with loops that

can be solved with recursion.

For example, summing the elements in an array. The book contains a recursive algorithm to do this.

Review Questions

1. Define “Variable Scope.”

The area of the program where the variable is valid.

2. Define “Variable Storage Class.”

A Variable’s Storage Class defines how long the variable exists. It may be permanent or

temporary.

3. Why are hidden variables a bad idea?

They create confusion and readability problems.

4. What is the scope of a function’s parameters?

The scope of function parameters are limited to the body of the function.

5. What is the class of a function’s parameters?

Temporary.

6. The keyword static changes a local variable’s storage class from __________ to __________.

“ Temporary” to “permanent.”

7. Why are all global variables permanent?

A better question might be: “How could we possibly make them temporary?” Temporary

variables are created and destroyed as needed. Global variables are always “needed” so

there is no way of creating and destroying them.

8. When is the following variable created, initialized, and destroyed?

int funct(void) {

int var = 0 // The variable in question

// ......

The variable is created when the function is called. It is initialized every time the function

You've reached the end of published parts.

⏰ Last updated: Nov 04, 2012 ⏰

Add this story to your Library to get notified about new parts!

Practical C++ Programming by manish baranwalWhere stories live. Discover now