C++ Primer - Chapter 1 (Getting Started) Flashcards

1
Q

A function definition consists of what four parts?

A

A return argument, a function name (identifier), a parameter list (which may be empty), and a function body.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is an “argument”?

A

A value passed to a function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does “assignment” do?

A

Obliterates an object’s current value and replaces that value by a new one.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a “block” of code?

A

Sequence of zero or more statements enclosed in curly braces.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a “buffer”? Give an example of where a buffer is used.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is “cerr”?

A

An ostream object tied to the standard error, which often writes to the same device as the standard output.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a “character string literal”?

A

A sequence of characters enclosed by double quotation marks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is “cin”?

A

An istream object used to read from the standard input.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is “clog”?

A

An ostream object tied to the standard error.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the edit-compile-debug process?

A

The process of getting a program to execute properly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is an end-of-file?

A

System-specific marker that indicates that there is no more input in a file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is an “expression”?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a header?

A

Mechanism whereby the definitions of a class or other names are made available to multiple programs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does it mean to “initialise”?

A

Give an object a value at the same time that it is created.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a stream manipulator?

A

An object, such as std::endl, that when read or written “manipulates” the stream itself.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a method?

A

A synonym for member function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is a namespace?

A

Mechanism for putting names defined by a library into a single place.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is a parameter list?

A

Part of the definition of a function; a (possibly empty) list that specifies what arguments can be used to call the function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is a source file?

A

A file that contains a C++ program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is an uninitialised variable?

A

A variable that is not given an initial value.

21
Q

What is the () operator called?

A

Call operator. A pair of parentheses “()” following a function name.

22
Q

What is the :: operator called?

A

Scope operator.

23
Q

Define “#include”

A

A directive that makes code in a file available to a program.

24
Q

Name the four IO objects defined in the iostream library.

A

cin, cout, cerr, clog

25
Q

What is a stream?

A

A sequence of characters read from or written to an IO device.

26
Q

Is the result of an ostream or istream output the left or right operand of the&raquo_space; operator?

A

Left-hand operand.

27
Q

What is the endl operator?

A

A stream manipulator; it ends the current line and flushes the buffer.

28
Q

Where are include directives typically written?

A

At the top of a file.

29
Q

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

A return value of 0 indicates program success. A return value >0 indicates program failure; the value is normally the type of error encountered.

30
Q

Why should std::cout statements used during debugging always use std::endl and not “\n”?

A

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.

31
Q

What is the general syntax of a while loop?

A

while (condition){ statement }

32
Q

What is the general syntax of a for loop?

A

for (init-statement; condition; expression){ body }

33
Q

How can an unknown number of inputs be read in to a C++ program?

A

With a while loop of the form:while (std::cin&raquo_space; input){ body }

34
Q

What happens to an istream when it hits an end-of-file?

A

It becomes invalid; causing conditions to return the value false.

35
Q

What is the difference between ‘a’ and “a” in C++?

A

‘a’ is a character and “a” is a string literal which is represented with two characters: ‘a’ and ‘\0’.

36
Q

What character is automatically appended to the end of a string?

A

The ‘\0’ character.

37
Q

If data is held by cout in the buffer and cin is called, what happens to the data?

A

By default, reading cin flushes cout, forcing the buffer to be written. Note: cout is also flushed when the program ends normally.

38
Q

How are variables of class type initialised if no initial value is specified?

A

It is default initialised using the class definition.

39
Q

How is a variable of built-in type, which is defined outside a function, initialised when no initial value is provided?

A

Variables of a built-in type defined outside a function are default initialised to zero.

40
Q

True or false? It is not an error to use the value of an uninitialised variable.

A

False. It is an error to try to use the value of an uninitialised variable.

41
Q

Are writes to cerr are buffered?

A

No. By default, writes to cerr are not buffered.

42
Q

What is cerr typically used for?

A

cerr is typically used for error messages or other output that is not part of the normal logic of the program.

43
Q

Are writes to clog buffered?

A

Unlike cerr, writes to clog are, by default, buffered.

44
Q

How is a header used in a program?

A

A program uses a header through a #include directive.

45
Q

Why is a namespace helpful?

A

Namespaces help avoid inadvertent name clashes.

46
Q

What is the call operator used for?

A

The call operator causes a function to be invoked. Arguments to the function may be passed inside the parentheses.

47
Q

What is clog typically used for?

A

clog is usually used to report information about program execution to a log file.

48
Q

How is a variable of built-in type, which is defined inside a function, initialised when no initial value is provided?

A

Variables of a built-in type defined inside a function are uninitialised.