Practical C++ Programming by manish baranwal

Start from the beginning
                                        

3. What is the purpose of the return(0); near the end of each program?

It returns a status code of 0 (good return) to the operating system.

4. What punctuation character signals the end of each statement?

A semicolon (;).

5. What statement to you use to print something to the screen?

std::cou t s tatement .

6. What are the five simple C++ operators?

Multiplication (*), division (/), addition (+), subtraction (-), and modulus (%).

7. Evaluate the following C++ expressions:

a. 5 + 3 / 2 + 1

7

b. (5 + 3) / ( 2 + 1)

2

c. 8 % (3 * 4) + 8 / 3 - 9

1

Page 10

d. 8 / (3 * 4 + 8 / 3 - 9)

1

e. 4 + 9 * 6 - 8

50

f. (11 % 7) / 3

1

8. What will the following statements print? (Assume i=5 and j=7.)

a. std::cout << i << '

';

5

b. std::cout << "i" << '

';

c. std::cout << i / j << '

';

0

d. std::cout << "i=" << i;

i=5

Warning: There is no newline at the end of this statement, so the next std::cout output

will run right up against the 5. (Example: i=5Hello World .)

e. std::cout << "i=" << i << '

';

i=5

Notice that the newline is added, so this will be a complete line .

9. Turn the equation d=

1

2

⋅g t2

into a C++ statement.

d = 1.0 / 2.0 * g * t * t;

or using better variable names:

distance = 1.0 / 2.0 * GRAVITY * time * time;

10. What does it mean when you see the message “Warning: Null effect”?

A statement is correctly written, but useless. For example, a statement that computes a

value then throws it away.

11. Define “variable.”

A named area of memory used to store values.

Page 11

12. Define “variable declaration.”

A C++ statement that describes a variable. It is used to tell C++ what variables we are

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