Shared Flashcard Set

Details

chpt 13 & 14
-
115
Computer Science
Undergraduate 2
04/08/2013

Additional Computer Science Flashcards

 


 

Cards

Term
Pointer variable
Definition
A variable whose content is a memory address (memory space)
Term
What is the value of a pointer variable?
Definition
an address
Term
dataType *identifier
Definition
Syntax of a Pointer variable
Term
True or False: The character * can appear anywhere between type name and variable name in a pointer declaration.
Definition
True
Term
In the statement:
int* p, q;
What is q?
Definition
an int variable
Term
What two operators are used with pointers?
Definition
dereferencing (*) and address of (&)
Term
&
Definition
address of operator
Term
* (unary operator)
Definition
dereferencing operator or indirection operator
Term
the address of operator (&) does what?
Definition
returns the address of its operand
Term
In the following series of code:
int x;
int *p;
p=&x;
the value of p is equal to?
Definition
the value of x
Term
In the following series of code:
int x = 25;
p = &x;
cout << *p << endl;
What is printed?
Definition
25 (the value stored in the memory space pointed to by p, which is the value of x)
Term
In the following series of code:
int x = 25;
p = &x;
*p = 55;
Where else is 55 stored?
Definition
In x
Term
The Statement
int *p;
Allocates memory for what variable?
Definition
p
Term
The Statement
int *p;
Allocates memory for what variable?
Definition
p
Term
True or False: Pointers cannot be declared to classes.
Definition
False; They can.
Term
In the following series of code:
struct studentType
{
char name[26];
double gpa
int sID
cahr grade
};

studentType student;
studentType *studentPtr;

studentPtr = &student
(*studentPtr).gpa = 3.9;
3.9 is stored where?
Definition
in the gpa of the object student
Term
T or F: the dot operator has a higher precedence than the dereferencing operator
Definition
True
Term
In the expression (*studentPtr).gpa, why are there parentheses?
Definition
to stop the (.) dot operator from running before the (*) deferencing operator.
Term
T or F: Because studentPtr is a pointer variable of type studentType, *studentPtr, refers to a memory space of type studentType, which is a struct.
Definition
True
Term
->
Definition
member access operator arrow
Term
The purpose of ->
Definition
To eliminate the need for () and * when accessing class or struct components via a pointer.
Term
pointerVariableName->classMemberName
Definition
syntax for accessing a class(struct) member
Term
(*studentPtr).gpa=3.9 is equivalent to ?
Definition
studentPtr->gpa=3.9
Term
T or F: C++ automatically initializes variables
Definition
False
Term
Null pointer
Definition
pointer variable initialized using constant variable, 0
Term
What is the only number that can be assigned to a pointer variable?
Definition
0
Term
Dynamic variables
Definition
variables created during program execution
Term
in C++ how are dynamic variables created?
Definition
using pointers
Term
What two operators are used to create and destroy variables?
Definition
new and delete
Term
When is delete used?
Definition
when a dynamic variable is no longer needed
Term
What are the new operators two syntax forms?
Definition
new dataType;
new dataType[intExp];
Term
What two ways is new used?
Definition
to allocate a single variable, and to allocate an array of variables
Term
the statement:
p = new int;
does what two things?
Definition
creates a variable, p
stores the address of the newly allocated memory in p
Term
The following statement:
q = new char[16]
does what?
Definition
creates an array of 16 items of type “char” and store the base address of the array in the pointer variable q
Term
The operator new does what?
Definition
allocates memory space of a specific type and returns the (starting) address of the allocated memory space.
Term
If the operator new is unable to allocate the required memory space what happens?
Definition
then it throws bad_alloc exception
Term
if the bad_alloc exception is not handled what happens?
Definition
it terminates the program with an error message.
Term
memory leak
Definition
when unused memory space exists, but cannot be reallocated
Term
a large amount of memory leak may result in?
Definition
The program running out of memory and resulting in abnormal termination of the program
Term
To avoid memory leak, you should use what operator?
Definition
delete
Term
What are the two syntax forms of delete?
Definition
delete pointerVariable;
delete [] pointerVariable;
Term
Why is it a good idea to set the value of all deleted pointers to ‘Null”?
Definition
because on some systems the pointer variable might still hold the address of the deallocated memory space. (dangling)
Term
Assignment
Definition
value of one pointer variable can be assigned to another pointer of same type
Term
Relational operations
Definition
two pointer variables of same type can be compared for equality, etc.
Term
T or F: Integer values can be added and subtracted from a pointer variable
Definition
True
Term
T or F: Value of one pointer variable can be subtracted from another pointer variable
Definition
True
Term
in the following series of code:
int *p, *q;
p = q;
If changes are made to *p, what happens to *q
Definition
The same changes apply to *q
Term
in the following statement:
int *p, *q;
The statement p==q; evaluates to what?
Definition
True, if p and q point to the same memory location
Term
in the following statement:
int *p, *q;
The statement p!=q; evaluates to what?
Definition
true if p and q point to a different memory location.
Term
In the following series of code:
int *p;
double *q
char *chPtr
studentType * stdPtr
the statement p++; increments p by how much? Why?
Definition
4 bytes because it is type int
Term
In the following series of code:
int *p;
double *q
char *chPtr
studentType * stdPtr
the statement q++; increments q by how much? Why?
Definition
8 bytes because it is type double
Term
In the following series of code:
int *p;
double *q
char *chPtr
studentType * stdPtr
the statement chPtr++; increments chPtr by how much? Why?
Definition
1 byte because it is type string
Term
In the following series of code:
int *p;
double *q
char *chPtr
studentType * stdPtr
the statement stdPtr++; increments stdPtr by how much? Why?
Definition
40 bytes because it is points to a class
Term
When an integer is added to a pointer variable, the value of the pointer variable is incremented by how much?
Definition
by the integer times the size of the memory that the pointer is pointing to.
Term
When an integer is subtracted from a pointer variable, the value of the pointer variable is decremented by how much?
Definition
by the integer times the size of the memory to which the pointer is pointing.
Term
T or F: Pointer arithmetic is very safe.
Definition
False
Term
T or F: Using pointer arithmetic, the program can accidentally access the memory locations of other variables and change their content without warning, leaving the programmer trying to find out what went wrong.
Definition
True
Term
T or F: If a pointer variable tries to access either the memory spaces of other variables or an illegal memory space, some systems might terminate the program with an appropriate error message.
Definition
True
Term
dynamic array
Definition
An array created during the execution of a program
Term
When a dynamic array is created, what is stored in the pointer variable?
Definition
its base address
Term
In the following statement:
p = new int[10];
The statement *p = 25; stores 25 where?
Definition
in the first memory location
Term
In the following statement:
p = new int[10];
The statements:
p++;
*p = 25;
stores 25 where?
Definition
in the second memory location
Term
You can access the components of the array with what operations?
Definition
the increment and decrement operations
Term
What can be used to access memory locations in dynamic arrays?
Definition
array notation
Term
in an array, can the base address be altered during program execution?
Definition
no; it is constant
Term
t or F: An array name is a constant pointer and therefore cannot be altered.
Definition
True
Term
A pointer variable can be passed what two ways?
Definition
as a parameter either by value or by reference
Term
How do you make a pointer a reference parameter?
Definition
Place * before a & between the data type name and the identifier
Term
T or F: A function can return a value of type pointer
Definition
true
Term
In the following statement:
int *board[4];
what has been done?
Definition
This statement declares board to be an array of four pointers wherein each pointer is of type int.(board[0], board[1], board[2], and board[3] are pointers.)
Term
In the following series of code:
int *board[4];
for(int row = 0; row < 4; row++)
board[row] = new int[6];
what has been done?
Definition
The statement makes a two dimensional array with 4 rows and 6 columns
Term
In the following series of code:
int *board[4];
for(int row = 0; row < 4; row++)
board[row] = new int[6];
The array created is not a true dynamic two dimensional array. Why?
Definition
Because the number of rows is fixed
Term
In the following statement:
int **board;
what has been done?
Definition
board is a pointer to a pointer, meaning board and *board are pointers.
Term
In the following statement:
int **board;
to make board an array of 10 rows 15 columns, what has been done?
Definition
board = new int* [10];
for (row = 0;row < 10; row++)
board[row] = new int[15];
Term
In the following statement:
int **board;
what can be stored in board?
Definition
The address of an pointer or an array of pointers
Term
In the following statement:
int **board;
what can be stored in *board?
Definition
the address of an int memory space or an array of int values.
Term
What is the more efficient way of declaring a dynamic two-dimensional array?
Definition
int **board
Term
In a shallow copy, what takes place?
Definition
2 or more pointers of the same type point to the same memory
Term
In the following series of code:
int *first;
int *second;

first = new int[10];
second = first;
what has taken place?
Definition
a shallow copy of the array pointed to by first to the pointer second.
Term
In the following series of code:
int *first;
int *second;

first = new int[10];
second = first;
delete [] second;
what has taken place?
Definition
a shallow copy of the array pointed to by first to the pointer second then both arrays are deleted.
Term
In the following series of code:
second = new int[10];

for (int j = 0; j < 10; j++)
second[j] = first[j]
what has taken place?
Definition
a deep copy, both pointers have their own data.
Term
How do we ensure that the dynamic memory of a pointer variable is destroyed after it itself is destroyed?
Definition
destructor
Term
In default member-wise initialization for each class, the compiler provides what?
Definition
a default copy constructor that copies each member of the original object into the corresponding member of the new object
Term
In the fopllowing statement:
pointerDataClass objectThree(objectOne);
the object objectThree is being declared and is also being initialized by using the value of objectOne of the same type. What type of initialization is this?
Definition
default member-wise initialization.
Term
the object objectThree is being declared and is also being initialized by using the value of objectOne of the same type. What happens to the variables of objectOne
Definition
The values of the member variables of objectOne are copied into the corresponding member variables of objectThree.
Term
In static binding (compile-time binding), what occurs?
Definition
the necessary code to call a specific function is generated by the compiler.
Term
T or F: In run-­time (dynamic) binding,the compiler generates the code to call a specific function.
Definition
False
Term
In run-time (dynamic) binding, what occurs?
Definition
the compiler generates enough information to enable the run-­time system to generate the specific code for the appropriate function call.
Term
What is the purpose of a virtual function?
Definition
it acts as a placeholder that is meant to be redefined by derived classes.
Term
What do virtual functions prevent?
Definition
the inclusion of the definitions of the
referenced functions and the
user from creating objects of
the referenced class.
Term
A class with one or more pure virtual classes is called what?
Definition
an abstract class
Term
Overloading operators consists of what?
Definition
applying operators to classes, such as relational operators.
Term
returnType operator operatorSymbol(formal parameter list)
Definition
syntax for operator function
Term
What is an operator function?
Definition
The function that overloads an operator
Term
the name of the function to overload the operator >= is what?
Definition
operator>=
Term
T or F: You can change the precedence and associativity of an operator
Definition
False. You can't change either
Term
T or F: Default parameters cannot be used with an overloaded operator
Definition
True
Term
T or F: You can change the number of parameters an operator takes
Definition
False
Term
T or F: You cannot create new operators. Only existing ones can be overloaded.
Definition
True
Term
What operators cannot be overloaded?
Definition
., .*, ::, ?:, sizeof
Term
T or F: Operators can be overloaded either for objects of the user-defined types or for a combo of user-defined and objects of built-in type.
Definition
True
Term
Every object of a class maintains a (hidden) pointer to itself called what?
Definition
this
Term
When is the this pointer to an object referenced by the member function?
Definition
When that object invokes a member function
Term
if x is an object, this refers to what property of x?
Definition
Its address
Term
if x is an object, *this refers to what property of x?
Definition
Its value
Term
What is a friend function?
Definition
nonmember function of the class, but has access to all the members (public or non-­‐public) of the class
Term
How do you make a function a friend to a class?
Definition
friend precedes the function prototype
Term
post increment operator
Definition
the value of the variable is incremented by 1 after it is used in an expression
Term
Pre increment operator
Definition
the value of the variable is incremented by 1 before it is used in an expression
Term
className operator++();
Definition
syntax of prototype for post-increment operator
Term
className operator++(int);
Definition
syntax of prototype for pre-increment operator
Term
Templates
Definition
a single code body for a set of related functions
Term
template (arrow)class Type(arrow)
declaration
Definition
syntax for a template
Term
T or F: a implementation file with (a) template(s) can be independently compiled
Definition
false
Term
where are two places that a templates contenes be placed?
Definition
directly in the client code, or directly in the header file.
Supporting users have an ad free experience!