-
What is the purpose of comments and how are they denoted?
// Comment lines begin with // because it tells the program to skip the line. They can also be written across several lines with /* and */
Comments document programs and improve readability.
-
What is a preprocessor directive? Give an example.
They are processed by the preprocessor before the program is compiled. They begin with a #. They do not end with a semi-colon.
#include
-
What does the line #include
do?
It tells the preprocessor to include the input/output stream header in the program.
It allows std::cin and std::cout and operators << and >> to be used in the program.
-
What is the purpose of white-space?
White space makes programmers easier to read. They are ignored by the compiler.
-
What is main ?
The program begins executing at main even if it does not appear first in the program.
-
What does the keyword int do?
Returns an integer value.
-
Explain the purpose of braces. { }
The left brace { begins the body of the function.
The right brace } ends the body of the function.
-
What are other names for a "string"?
A character string, message string, or string literal.
-
What is a statement terminator?
Every statement must end with a semicolon.
-
What is the output stream object?
std::cout
-
What is the input stream object?
std::cin
-
How are multiple data items concatated for output?
With stream insertion operators.
<<
-
How are multiple data items concatated for input?
With stream extraction operators.
>>
-
std::cout is normally connected to which hardware device?
the screen for output
-
std::cin is normally connected to which hardware device?
the keyboard for input
-
What is conversational computing (or interactive computing)?
Interaction between the user and the computer.
- examples:
- std::cout std::cin
-
How is an escape sequence formed and what does it do?
An escape sequence is formed from a backslash \ and the next character.
-
Define prompt.
A message that directs the user to take a specific action.
-
Define the keyword
return
(one of several means to) exit a function
-
All variables in a C++ program must be _________ before they can be used.
declared
-
What are the rules for naming a variable in C++?
- can contain letters, digits, and underscores (_)
- cannot start with a digit
- can be any length (some systems may impose limits on length)
- cannot be one of the preset names (such as cout)
-
Is C++ case sensitive?
Yes, C++ is case sensitive.
-
Where are calculations performed?
Most calculations are performed in assignment statements.
-
What is the name of a location in the computer's memory where a value can stored for use by a program?
a variable
-
What does the variable int hold?
integer values, i.e. whole numbers
-
Every variable stored in the computer's memory has:
1)
2)
3)
4)
- 1) a name
- 2) a value
- 3) a type
- 4) a size
-
What does it mean when the process is nondestructive?
A copy of the value is read, leaving the original value undisturbed.
(keyword = read)
-
What does it mean with the process is destructive?
The new value replaced the previous value in that location. The previous value is lost.
(think: write)
-
What does the std::endl stream manipulator do?
Outputs a newline, then flushes the output buffer.
-
What are the order of operations for C++ arithmetic expressions?
- ( ) (nested first)
- * / % (from left to right)
- + - (from left to right)
-
When dividing integers in C++, does it return a decimal, fraction, or neither? Does it round the integer to the nearest whole number?
None of the above. Any fractional part of the answer is truncated and no rounding occurs.
- i.e.
- mathematical answer: 346.875
- C++ answer: 346
-
What is the purpose of the modulus operator? What is the symbol used?
The modulus operator, or %, yields the remainder after integer division. (It can only be used with integers.)
- mathematical answer: 346.875
- C++ % answer: 875
-
What is an
if
statement? What is the format for using one?
It allows a program to make a decision when a certain condition is met. If the condition is true, the statement in the body of the statement is executed. If it is not true, the statement is skipped.
- if (condition)
- statement;
-
What is a relational operator? What is an equality operator? Which one has precedence?
- Relational Operators: > and < and derivatives
- Equality Operators: = and derivatives
- Relational operators have precedence.
-
What is the purpose of the declaration using
std::cout;
at the beginning of the program?
The declaration eliminates the need to repeat the
std::
prefix. All that needs to be written thereafter is
cout
|
|