• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/85

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

85 Cards in this Set

  • Front
  • Back
member function substr() for
retrieving a substring from a string.
The new result is a new string object that is copied from the source string.
10 int main()
11 {
12 string string1( ”The airplane landed on time.” );
13
14 // retrieve substring ”plane” which
15 // begins at subscript 7 and consists of 5 characters
16 cout << string1.substr( 7, 5 ) << endl;

does what?
It is using a substring function to display the string at line 16
Pointer variables contain memory ____ as their values.
addresses as their values.
Normally, a variable directly contains a specific value. However, a pointer contains the memory address of a variable that, in turn, contains a
specific value.
a pointer _______references a value
indirectly
a variable name ______references a value
directly
Referencing a value through a pointer is often called
indirection
Pointers, like any other variables, must be ______before they can be used.
declared

for example

int *countPtr, count;

declares the variable countPtr to be of type int
Each variable being declared as a pointer must be preceded by an
asterisk (*)
double *xPtr, *yPtr;

indicates?
indicates that both xPtr and yPtr are pointers to double values.
Although it is not a requirement, including the letters ___ in pointer variable names makes it clear that these variables are pointers and that they must be handled accordingly.
Ptr
Pointers should be initialized either when they are
declared or in an assignment.
A pointer may be initialized to
0, NULL or an address of the corresponding type.
A pointer with the value 0 or NULL points to nothing and is known as a
null pointer.
Symbolic constant NULL is defined in header file _______ to represent the value 0.
<iostream>
Initializing a pointer to NULL is equivalent to initializing a pointer to
0
The value 0 is the only integer value that can be assigned directly to a pointer variable without first casting the
integer to a pointer type.
The address operator ____ is a unary operator that obtains the memory address of its operand
(&)
When declaring a reference, the & is part of the
type
something to which a value can be assigned, such as a variable name or a reference
lvalue
the address operator cannot be applied
to constants or to expressions that do not result in references.
The * operator, commonly referred to as the
indirection operator or dereferencing operator
The * operator (indirection operator or dereferencing operator) returns what?
returns a synonym (i.e., an alias or a nickname) for the object to which its pointer operand points.
int y = 5;
int *yPtr;
yPtr = &y;

the statement

cout << *yPtr << endl;

prints the ?
prints the value of variable y, namely, 5, just as the statement

cout << y << endl;
cout << *yPtr << endl;

Using * in this manner is called
dereferencing a pointer.
a dereferenced pointer may also be used on the left side of an assignment statement, as in

*yPtr = 9;

which would
which would assign 9 to y
Dereferencing a pointer that has not been properly initialized or that has not been assigned to point to a specific location in memory could cause
a fatal execution-time error, or it could accidentally modify important data and allow the program to run to completion, possibly with incorrect results.
There are three ways in C++ to pass arguments to a function—
pass-by-value, pass-by-reference with reference arguments and pass-by-reference with pointer arguments.
In C++, programmers can use pointers and the indirection operator (*) to accomplish
pass-by-reference
When calling a function with an argument that should be modified, the address of the argument is passed. This is normally accomplished by
This is normally accomplished by applying the address operator (&) to the name of the variable whose value will be modified.
arrays are not passed using operator &, because
the name of the array is the starting location in memory of the array
Not dereferencing a pointer when it is necessary to do so to obtain the value to which the pointer points is an
error.
A function receiving an address as an argument must define
a pointer parameter to receive the address.
Always award a function enough access to the data in its parameters to accomplish its specified task, but
no more.
The size of the array is used in the function body to determine the highest subscript of the array so the loop can terminate when the printing completes. The size of the array does not change in the function body, so
it should be declared const.
the array is only being printed, it, too, should be declared ____.

This is important because
const

This is especially important because an entire array is always passed by reference and could easily be changed in the called function.
If a value does not (or should not) change in the body of a function to which it is passed, the parameter should be declared ----- to ensure that it is not accidentally modified.
const
There are four ways to pass a pointer to a function:
a nonconstant pointer to nonconstant data, a nonconstant pointer to constant data , a constant pointer to nonconstant data and a constant pointer to constant data (
The highest access is granted by
a nonconstant pointer to nonconstant data
in a nonconstant pointer to nonconstant data

The declaration for such a pointer does not include _____
the data can be modified through the dereferenced pointer, and the pointer can be modified to point to other data.


const
nonconstant pointer to nonconstant data pointer can used to receive a ______ ______ ______ in a function that changes the pointer to process ( and possibly modify) each character of the string.
null-terminated string
A nonconstant pointer to constant data is a pointer that can be modified to point to any data item of the appropriate type, but the
data to which it points cannot be modified through that pointer.
A nonconstant pointer to constant data might be used to
receive an array argument to a function that will process each element of the array, but should not be allowed to modify the data.
A constant pointer to nonconstant data is a
pointer that always points to the same memory location; the data at that location can be modified through the pointer.

An example would be an array name.
A constant pointer to nonconstant data can be used to receive an array as an
argument to a function that accesses array elements using array subscript notation.
The least amount of access privilege is granted by a
constant pointer to constant data.
C++ provides the unary operator ______ to determine the size of an array (or of any other data type, variable or constant) in bytes during program compilation.
sizeof
When applied to the name of an array, the sizeof operator returns the total number of bytes in the array as a value of type _____
size_t
size_t is
an unsigned integer type that is at least as big as unsigned int
Operator sizeof can be applied to
any expression or type name.
When sizeof is applied to a variable name (which is not an array name) or other expression, the number of
bytes used to store the specific type of the expression’s value is returned.
sizeof is an operator, not a function, and that it has its effect at
at compile time, not execution time.
Pointers are valid operands in



but
arithmetic expressions, assignment expressions and comparison expression

not all the operators normally used in these expressions are valid with pointer variables.
Several arithmetic operations may be performed on pointers. A pointer may be
incremented (++) or decremented (--), an integer may be added to a pointer (+ or +=), an integer may be subtracted from a pointer (- or -=) or one pointer may be subtracted from another of the same type.
When an integer is added to, or subtracted from, a pointer, the pointer is not simply incremented or decremented by that integer, but by that integer times the
the size of the object to which the pointer refers.
The number of bytes depends on the object’s data type. For example, the statement

vPtr += 2;

would produce
3008 (3000 + 2 * 4), assuming that an int is stored in four bytes of memory.
Each of the statements

++vPtr;
vPtr++;
increments the pointer to point to the next element of the array.
Each of the statements

--vPtr;
vPtr--;
decrements the pointer to point to the previous element of the array.
Pointer variables pointing to the same ____ may be subtracted from one another.
array
Using pointer arithmetic on a pointer that does not refer to an array of values is a .
logic error
Subtracting or comparing two pointers that do not refer to elements of the same array is a
logic error.
A pointer can be assigned to another pointer if both pointers are of the same type. Otherwise, a
cast operator must be used to convert the value of the pointer on the right of the assignment to the pointer type on the left of the assignment.
All pointer types can be assigned to a pointer of type void *
without casting.
a pointer of type void * cannot be assigned directly to a pointer of another type—the pointer of type void * must first be
cast to the proper pointer type.
A void * pointer cannot be
dereferenced.
Pointers can be compared using .
equality and relational operators

comparisons using relational operators are meaningless unless the pointers point to members of the same array.
Arrays and pointers are intimately related in C++ and may be used almost .
interchangeably
An array name can be thought of as a
constant pointer.
Pointers can be used to do any operation involving
array subscripting.
Array element b[ 3 ] can alternatively be referenced with the pointer expression

*( bPtr + 3 )

The 3 in the preceding expression is the
offset to the pointer.
When the pointer points to the beginning of an array, the offset indicates which element of the array should be
referenced, and the offset value is identical to the array subscript.


known as the pointer/offset notation
Pointers can be subscripted exactly as arrays can. For example, the expression

bPtr[ 1 ]

refers to the array element b[ 1 ]; this expression uses
pointer/subscript notation.
an array name is a
constant pointer
an array name is a constant pointer; it always
it always points to the beginning of the array.
pointers can be modified in arithmetic expressions, array names
cannot be modified in arithmetic expressions because array names are constant pointers
Arrays may contain pointers. A common use of such a data structure is to form an array of pointer-based strings, referred to simply as a
string array.
each entry in an array of strings is simply a pointer to the
first character of a string.
String arrays are commonly used with ________ that are passed to function main when a program begins execution.
command-line arguments
type-safe I/O.
Each I/O operation is executed in a manner sensitive to the data type. If an I/O member function has been defined to handle a particular data type, then that member function is called to handle that data type. If there is no match between the type of the actual data and a function for handling that data type, the compiler generates an error

Thus, improper data cannot “sneak” through the system (as can occur in C, allowing for some subtle and bizarre errors).
Low-level I/O capabilities (i.e., unformatted I/O) specify that some number of bytes should be
transferred device-to-memory or memory-to-device.

In such transfers, the individual byte is the item of interest
low-level I/O capabilities provide
high-speed, high-volume transfers but are not particularly convenient for programmers.
Programmers generally prefer a higher-level view of I/O (i.e., formatted I/O), in which bytes are
grouped into meaningful units, such as integers, floating-point numbers, characters, strings and user-defined types.
use unformatted I/O for the
best performance in high-volume file processing.
Using unformatted I/O can lead to portability problems, because
unformatted data is not portable across all platforms.
classic stream libraries enabled input and output of chars. Because a char normally occupies one byte, it can represent
only a limited set of characters (such as those in the ASCII character set).