1/132
Looks like no tags are added yet.
With pointer variables you can access but not modify data in other variables
-true
-false
false
An array name is a pointer constant because the address stored in it cannot be changed at runtime.
-true
-false
true
In C++11, the nullptr keyword was introduced to represent the address 0.
-true
-false
true
It is legal to subtract a pointer variable from another pointer variable.
-true
-false
true
C++ does not perform array bounds checking, making it possible for you to assign a pointer the address of an element out of the boundaries of an array.
-true
-false
true
A pointer can be used as a function argument, giving the function access to the original argument.
-true
-fasle
true
The ampersand (&) is used to dereference a pointer variable in C++
-true
-false
false
Assuming myValues is an array of int values and index is an int variable, both of the following statements do the same thing.
1. cout << myValue [index] << endl;
2. cout << *(myValues + index) << endl;
-true
-false
true
In C++11 you can use smart pointers to dynamically allocate memory and not worry about deleting the memory when you are finished using it.
-true
-false
true
The weak_ptr can share ownership of a piece of dynamically allocated memory.
-true
-fasle
false
The unique_ptr is the sole owner of a piece of dynamically allocated memory.
-true
-false
true
To use any of the smart pointers in C++11 you must use the following directive in the header file:
-true
-false
true
The ________, also known as the address operator, returns the memory address of a variable.
astreric(*)
ampersand (&)
percent(%)
exclamation point(!)
none of these
ampersand(&)
With pointer variables you can ________ manipulate data stored in other variables.
never
seldom
indirectly
All of these
None of these
indirectly
When you work with a dereferenced pointer, you are actually working with
a)a variable whose memory has been allocated
b)a copy of the value pointed to by the pointer variable
c) the actual value of the variable whose address is stored in the pointer variable
d) None of these
c) the actual value of the variable whose address is stored in the pointer variable
A function may return a pointer but the programmer must ensure that the pointer
a)still points to a valid object after the function ends
b)has not been assigned an address
c)was received as a parameter by the function
d)has not previously been returned by another function
e) None of these
a)still points to a valid object after the function ends
What does the following statement do?
double *num2;
a)Declares a double variable named num2
b)Declares and initializes a pointer variable named num2
c)Initializes a pointer variable named num2
d)Declares a pointer variable named num2
e)None of these
d)Declares a pointer variable named num2
In C++11, the ________ keyword was introduced to represent address 0.
a)nullptr
b)NULL
c)weak_ptr
d)shared_ptr
e)None of these
a)nullptr
When the less than operator (<) is used between two pointer values, the expression is testing whether
a)the value pointed to by the first is less than the value pointed to by the second
b)the value pointed to by the first is greater than the value pointed to by the second
c)the address of the first variable comes before the address of the second variable in the computer's memory
d)the first variable was declared before the second variable
e)None of these
c)the address of the first variable comes before the address of the second variable in the computer's memory
Use the delete operator only on pointers that were
a)never used
b)not correctly initialized
c)created with the new operator
d)dereferenced inappropriately
e)None of these
c)created with the new operator
Which of the following is TRUE about this statement?
sum += *array++;
a)This statement is illegal in C++.
b)This statement will cause a compiler error.
c)This statement assigns the dereferenced pointer's value, then increments the pointer's address.
d)This statement increments the dereferenced pointer's value by one, then assign that value.
e)None of these
c)This statement assigns the dereferenced pointer's value, then increments the pointer's address.
In the following statement, what does int mean?
int *ptr = nullptr;
a)The variable named *ptr will store an integer value.
b)The variable named *ptr will store an asterisk and an integer value
c)ptr is a pointer variable and will store the address of an integer variable.
d)The variable named *ptr will store the value in nullptr.
e)None of these
c)ptr is a pointer variable and will store the address of an integer variable.
Assuming ptr is a pointer variable, what will the following statement output?
cout << *ptr;
a)the value stored in the variable whose address is contained in ptr
b)the string "*ptr"
c)the address of the variable whose address is stored in ptr
d)the address of the variable stored in ptr
e)None of these
a)the value stored in the variable whose address is contained in ptr
Which of the following statements is NOT valid C++ code?
a)int ptr = &num1;
b)int ptr = int *num1;
c)float num1 = &ptr2;
e)All of these are invalid
e)All of these are invalid
Which of the following statements deletes memory that has been dynamically allocated for an array?
a)int array = delete memory;
b)int delete[ ];
c)delete [] array;
d)new array = delete;
e)None of these
c)delete [] array;
Which of the following statements displays the address of the variable numb?
a)cout << numb;
b)cout << *numb;
c) cin >> &numb;
d)cout << &numb;
e)None of these
d)cout << &numb;
What will the following statement output?
a)cout << &num1;
b)the value stored in the variable named num1
c)the memory address of the variable named num1
the number 1
d)the string &num1
e)None of these
c)the memory address of the variable named num1
the number 1
The following statement ________.
cin >> *num3;
-stores the keyboard input in the variable num3
-stores the keyboard input into the pointer num3
is illegal in C++
-stores the keyboard input into the variable pointed to by num3
- None of these
-stores the keyboard input into the pointer num3
is illegal in C++
The following statement ________.
int *ptr = new int;
results in a compiler error
assigns an integer less than 32767 to the variable ptr
assigns an address to the variable ptr
creates a new pointer named int
None of these
assigns an address to the variable ptr
A pointer variable is designed to store
any legal C++ value
only floating-point values
an integer
a memory address
None of these
memory address
The ________ and ________ operators can be used to increment or decrement a pointer variable.
] addition, subtraction
++, --
modulus, division
All of these
None of these
++, --
Not all arithmetic operations can be performed on pointers. For example, you cannot ________ or ________ pointers.
multiply, divide
+=, -=
add, subtract
increment, decrement
None of these
multipy, divide
Dynamic memory allocation occurs
when a new variable is created by the compiler
when a new variable is created at runtime
when a pointer fails to dereference the right variable
when a pointer is assigned an incorrect address
None of these
when a new variable is created at runtime
Every byte in the computer's memory is assigned a unique
pointer
address
dynamic allocation
name
None of these
address
A pointer variable may be initialized with
any nonzero integer value
a valid address in the computer's memory
an address less than zero
any nonzero number
None of these
a valid address in the computer's memory
If a variable uses more than one byte of memory, for pointer purposes its address is
the address of the last byte of storage
the average of all the addresses used to store that variable
the address of the first byte of storage
the address of the second byte of storage
None of these
the address of the first byte of storage
If you are using an older computer that does NOT support the C++11 standard, you should initialize pointers with
the integer 0 or the value NULL
the null terminator '\0'
a nonzero value
Any of these
None of these
the integer 0 or the value NULL
When you pass a pointer as an argument to a function, you must
declare the pointer value again in the function call
dereference the pointer value in the function prototype
use the #include statement
not dereference the pointer in the function's body
None of these
none
To help prevent memory leaks from occurring in C++11, a ________ automatically deletes a chunk of dynamically allocated memory when the memory is no longer being used.
null pointer
smart pointer
dereferenced pointer
None of these
smart pointer
What will the following code output?
int number = 22;
int *var = &number;
cout << *var << endl;
the address of number
22
an asterisk followed by 22
an asterisk followed by the address of number
22
What will the following code output?
int number = 22;
int *var = &number;
cout << var << endl;
the address of number
22
an asterisk followed by 22
an asterisk followed by the address of number
the address of number
What will the following code output?
int *numbers = new int[5];
for (int i = 0; i <= 4; i ++)
*(numbers + i) = i;
cout << numbers[2] << endl;
five memory addresses
0
3
2
1
2
After the code shown executes, which of the following statements is TRUE?
int numbers[] = {0, 1, 2, 3, 4};
int *ptr = numbers;
ptr++;
ptr will hold the address of numbers[0]
ptr will hold the address of the second byte within the element numbers[0]
ptr will hold the address of numbers[1]
this code will not compile
ptr will hold the address of numbers[1]
Which of the following defines a unique_ptr named uniq that points to a dynamically allocated int?
unique_ptr int( new int );
unique_ptr int( new uniq );
unique_ptr uniq( new int );
unique_ptr uniq( new int );
None of these
unique_ptr uniq( new int );
Which of the following can be used as pointers?
array names
numeric constants
keywords
None of these
array name
elect all that apply. Select as many of the following options that make this sentence TRUE:
The contents of pointer variables may be changed with mathematical statements that perform
multiplication
division
addition
subtraction
modulus
addition, subtraction
Select all that apply. Of the following, which statements have the same meaning?
int *ptr = nullptr;
int ptr = nullptr;
*int ptr = nullptr;
int* ptr = nullptr;
int ptr* = nullptr;
int *ptr = nullptr;
int* ptr = nullptr;
A struct can contain members with varying data types.
T
Any mathematical operation that can be performed on regular C++ variables can be performed
on structure members.
T
Structure variables may be passed as arguments to functions.
T
The structure pointer operator is used to dereference a pointer to a structure, not a pointer that is a member of a structure.
T
If a function is legally prototyped to return an integer value, it can return a structure member
that is an integer data type.
T
A function cannot modify the members of a structure.
F
The expression s->m; indicates that s is a structure pointer and m is a structure member.
T
It is possible to output the contents of all members of a structure variable using a cout <<
statement followed by the name of the structure variable.
F
When a programmer creates an abstract data type, he or she can decide what values are
acceptable for the data type, as well as what operations may be performed on the data type.
T
It is possible for a structure variable to be a member of another structure variable.
T
The expression *s->p; indicates that s is a structure pointer and p, which is also a pointer, is a member of the structure pointed to by s.
T
It is possible for a structure to contain, as a member, a pointer to its own structure type.
T
You cannot directly assign an integer value to an enum variable.
T
You cannot directly assign an enumerator to an int variable.
F
When you use a strongly typed enumerator in C++11 you must prefix the enumerator with the
name of the enum followed by the :: operator.
T
The names of enumerators in an enumerated data type must be enclosed in quotation marks.
F
In C++11 if you want to retrieve a strongly typed enumerator's underlying integer value, you
must use a cast operator.
T
Given the structure definition shown, assume that circle1 and circle2 are variables of
the Circle type and their members have been initialized.
struct Circle
{
double centerX;
double centerY;
double radius;
};
Then, is it true or false that the following statement correctly determines whether the two variables' members
contain the same data?
if (circle1 == circle2)
F
Which of the following describes only the general characteristics of an object?
a. initialization
b. abstraction
c. detailed specification
d. initiation
e. None of these
B
Which of the following is required after the closing brace of the structure definition?
a. square bracket
b. period
c. semicolon
d. colon
e. None of these
C
Which of the following is an example of a C++ primitive data type?
a. unsigned short int
b. long double
c. unsigned char
d. All of these
e. None of these
D
The following statement __________.
bookList[2].publisher[3] = 't';
a. is illegal in C++
b. will change the name of the second book in bookList to 't'
c. will store the character 't' in the fourth element of the publisher member of
bookList[2]
d. will result in a runtime error
e. None of these
C
When a structure is passed __________ to a function, its members are not copied.
a. by reference
b. by value
c. Either of these
d. Neither of these
A
Passing a structure as a constant reference parameter to a function
a. can potentially result in changes to the structure's members
b. guarantees not to result in changes to the structure's members
c. will always change the structure's members
d. None of these
B
You may use a pointer to a structure as a
a. function parameter
b. structure member
c. function return type
d. All of these
e. None of these
D
Data types that are created by the programmer are known as
a. variables
b. abstract data types (ADTs)
c. functions
d. parameters
e. None of these
B
Before a structure can be used it must be
a. declared
b. dereferenced
c. initialized
d. All of these
e. None of these
A
The name of a structure is referred to as its
a. data type
b. argument
c. parameter
d. tag
e. None of these
E
A function __________ return a structure.
a. may
b. may not
c. will always
d. can never
e. None of these
A
A structure pointer contains
a. the address of a structure variable
b. the dereferenced address of a structure tag
c. the name and address of the structure tag
d. the address of a structure tag
e. None of these
A
Which of the following assigns a value to the hourlyWage member of employee[2]?
a. employee[2] -> hourlyWage = 50.00;
b. employee2.hourlyWage = 7.50;
c. hourlyWage[2].employee = 29.75;
d. employee[2].hourlyWage = 75.00;
e. None of these
D
If Circle is a structure tag, then the following statement can be the header line for a function
that __________.
Circle doSomething(Circle c2)
a. determines and returns the area of a circle
b. takes a Circle structure as a parameter, does something, and returns a Circle
structure
c. operates on a constant reference to a Circle structure
d. takes two Circle parameters and does something
e. None of these
B
Which of the following will allow you to access structure members?
a. the structure access operator
b. the dot operator
c. the #include
d. the getmember function
e. None of these
B
To dereference a structure pointer, the appropriate operator is
a. the ampersand (&)
b. an asterisk (*)
c. the -> operator
d. the <- operator (<-)
e. None of these
C
If a is a structure variable and p, a pointer, is a member of the structure, what will the
following statement do?
cout << *a.p;
a. output the dereferenced value pointed to by p
b. result in a compiler error
c. output the address stored in p
d. output the value stored in a
e. None of these
A
A structure __________ contain members of the same data type.
a. cannot
b. can
c. shouldn't
d. None of these
B
Which of the following statements outputs the value of the gpa member of element [1] of the
student array?
a. cout << student1.gpa;
b. cout << firstStudent.gpa;
c. cout << student[1].gpa;
d. cout << student1->gpa;
e. None of these
C
If Circle is a structure, what does the following statement do?
Circle *pcirc = nullptr;
a. It declares an empty structure variable named *pcirc.
b. It declares a structure pointer called pcirc initialized with a null pointer.
c. The statement is illegal in C++.
d. It initializes a null pointer with the value of the Circle pointer.
e. None of these
B
A good reason to pass a structure as a constant reference is
a. to prevent changes to the structure's members
b. to ensure changes to the structure's members
c. to slow down the function's execution which helps prevent errors
d. to speed up the function's modification of the structure's members
e. None of these
A
With an enumerated data type, the enumerators are stored in memory as
a. strings
b. integers
c. characters
d. doubles
B
In C++11, you can use a new type of enum known as a(n) __________ (also known as an
enum class) to have multiple enumerators with the same name, within the same scope.
a. universal enum
b. auto enum
c. multi-cast enum
d. strongly typed enum
e. None of these
D
A declaration for an enumerated type begins with the __________ key word.
a. enumerated
b. enum_type
c. enum
d. ENUM
e. None of these
C
After the following statement executes, what value will the MAPLE enumerator be stored as, in
memory?
enum Tree { OAK, MAPLE, PINE };
a. "MAPLE"
b. 2
c. 'M'
d. 1
e. 1.0
D
Given the following decaration:
enum Tree { OAK, MAPLE, PINE };
What is the value of the following relational expression?
OAK > PINE
a. true
b. false
c. This is an error. You cannot compare enumerators with relational operators.
B
Given the following structure decaration, Employee is
struct Employee
{
string name;
int idNum;
};
a. a member
b. an array
c. a tag
d. None of these
C
Given the following structure decaration, idNum is
struct Employee
{
string name;
int idNum;
};
a. a member
b. an array
c. a tag
d. None of these
A
Given the structure
struct TwoVals
{
int a, b;
};
Select what is INCORRECT.
int main()
{
TwoVals tv;
tv.a =1;
tv.b =2;
}
int main()
{
TwoVals.a = 10;
TwoVals.b = 20;
return 0;
}
int main()
{
TwoVals * p = new TwoVals();
return 0;
}
int main()
{
TwoVals.a = 10;
TwoVals.b = 20;
return 0;
}
Select what is INCORRECT.
struct FourVals
{
int a, b, c, d;
};
int main ()
{
FourVals nums = {1, 2, , 4};
return 0;
}
int main ()
{
FourVals nums = {1, 2, 3};
return 0;
}
int main ()
{
FourVals nums = {1, 2, 3, 4};
return 0;
}
int main ()
{
FourVals nums;
return 0;
}
int main ()
{
FourVals nums = new FourVals();
return 0;
}
int main ()
{
FourVals nums = new FourVals();
return 0;
}
int main ()
{
FourVals nums = {1, 2, , 4};
return 0;
}
Destructors can take arguments.
false
When an array of 3 structures is declared
The constructor is called 3 times.
The constructor is called 0 times, you have to use operator new for the constructor to be called.
he constructor is called 1 time.
None of the answers is correct.
The constructor is called 3 times.
When a member function’s body is written inside a struct declaration, the function is _________.
embedded
inline
local
instance
inline
The destructor of structures is called automatically when a local vaiable goes out of scope
true
If the code below compiles what is the the value of ptr after execution?
int numbers[] = {0, 1, 2, 3, 4 };
int *ptr = numbers;
ptr++;
ptr will hold the address of numbers[0].
ptr will hold the address of the 2nd byte within the element numbers[0].
ptr will hold the address of numbers[1].
ptr will hold the address of numbers[1].