C++ Primer - Chapter 1 (Getting Started) Flashcards
A function definition consists of what four parts?
A return argument, a function name (identifier), a parameter list (which may be empty), and a function body.
What is an “argument”?
A value passed to a function.
What does “assignment” do?
Obliterates an object’s current value and replaces that value by a new one.
What is a “block” of code?
Sequence of zero or more statements enclosed in curly braces.
What is a “buffer”? Give an example of where a buffer is used.
A region of storage used to hold data. IO facilities often store input (or output) in a buffer and read or write the buffer independently from actions in the program.
What is “cerr”?
An ostream object tied to the standard error, which often writes to the same device as the standard output.
What is a “character string literal”?
A sequence of characters enclosed by double quotation marks.
What is “cin”?
An istream object used to read from the standard input.
What is “clog”?
An ostream object tied to the standard error.
What is the edit-compile-debug process?
The process of getting a program to execute properly.
What is an end-of-file?
System-specific marker that indicates that there is no more input in a file.
What is an “expression”?
The smallest unit of computation. An expression consists of one or more operands and usually one or more operators. Expressions are evaluated to produce a result.
What is a header?
Mechanism whereby the definitions of a class or other names are made available to multiple programs.
What does it mean to “initialise”?
Give an object a value at the same time that it is created.
What is a stream manipulator?
An object, such as std::endl, that when read or written “manipulates” the stream itself.
What is a method?
A synonym for member function.
What is a namespace?
Mechanism for putting names defined by a library into a single place.
What is a parameter list?
Part of the definition of a function; a (possibly empty) list that specifies what arguments can be used to call the function.
What is a source file?
A file that contains a C++ program.
What is an uninitialised variable?
A variable that is not given an initial value.
What is the () operator called?
Call operator. A pair of parentheses “()” following a function name.
What is the :: operator called?
Scope operator.
Define “#include”
A directive that makes code in a file available to a program.
Name the four IO objects defined in the iostream library.
cin, cout, cerr, clog
What is a stream?
A sequence of characters read from or written to an IO device.
Is the result of an ostream or istream output the left or right operand of the»_space; operator?
Left-hand operand.
What is the endl operator?
A stream manipulator; it ends the current line and flushes the buffer.
Where are include directives typically written?
At the top of a file.
What does a return value of zero from main() indicate? What does a non-zero value indicate? What does this non-zero value typically tell you?
A return value of 0 indicates program success. A return value >0 indicates program failure; the value is normally the type of error encountered.
Why should std::cout statements used during debugging always use std::endl and not “\n”?
Statements not using the std::endl manipulator won’t get immediately flushed to the output, and may instead be left sitting in the buffer when the program fails.
What is the general syntax of a while loop?
while (condition){ statement }
What is the general syntax of a for loop?
for (init-statement; condition; expression){ body }
How can an unknown number of inputs be read in to a C++ program?
With a while loop of the form:while (std::cin»_space; input){ body }
What happens to an istream when it hits an end-of-file?
It becomes invalid; causing conditions to return the value false.
What is the difference between ‘a’ and “a” in C++?
‘a’ is a character and “a” is a string literal which is represented with two characters: ‘a’ and ‘\0’.
What character is automatically appended to the end of a string?
The ‘\0’ character.
If data is held by cout in the buffer and cin is called, what happens to the data?
By default, reading cin flushes cout, forcing the buffer to be written. Note: cout is also flushed when the program ends normally.
How are variables of class type initialised if no initial value is specified?
It is default initialised using the class definition.
How is a variable of built-in type, which is defined outside a function, initialised when no initial value is provided?
Variables of a built-in type defined outside a function are default initialised to zero.
True or false? It is not an error to use the value of an uninitialised variable.
False. It is an error to try to use the value of an uninitialised variable.
Are writes to cerr are buffered?
No. By default, writes to cerr are not buffered.
What is cerr typically used for?
cerr is typically used for error messages or other output that is not part of the normal logic of the program.
Are writes to clog buffered?
Unlike cerr, writes to clog are, by default, buffered.
How is a header used in a program?
A program uses a header through a #include directive.
Why is a namespace helpful?
Namespaces help avoid inadvertent name clashes.
What is the call operator used for?
The call operator causes a function to be invoked. Arguments to the function may be passed inside the parentheses.
What is clog typically used for?
clog is usually used to report information about program execution to a log file.
How is a variable of built-in type, which is defined inside a function, initialised when no initial value is provided?
Variables of a built-in type defined inside a function are uninitialised.