380 likes | 391 Views
CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009. If a class is named MyClass , what must theconstructors be named? Initializer MyClass Any name the programmer wishes except the name of the class ~ MyClass None of the above.
E N D
CISC181 Introduction to Computer ScienceDr. McCoyLecture 19Clicker QuestionsNovember 3, 2009
If a class is named MyClass, what must theconstructors be named? • Initializer • MyClass • Any name the programmer wishes except the name of the class • ~MyClass • None of the above.
Referencing elements outside the array bounds (a) can result in changes to the value of an unrelated variable (b) is impossible because C++ checks to make sure it does not happen (c) is a syntax error (d) enlarges the size of the array
True/False Pointer variables are just memory addresses and can be assigned to one another without regard to type.
True/False Pointer variables are just memory addresses and can be assigned to one another without regard to type. Answer: False Explanation: A pointer variables, like everything else in C++ is typed, and that typing is enforced strongly. A pointer variable of type double* cannot normally hold a pointer value of type int* for example.
Strings cannot (a) be initialized using string literals (b) grow or shrink dynamically (c) be initialized with initializer lists (d) be treated as arrays of characters
Three of the following expressions have the same value. Which of the following’s value is different from the others? (a) *&Ptr (b) &*Ptr (c) *Ptr (d) Ptr
An array name is (a) a nonconstant pointer to nonconstant data (b) a nonconstant pointer to constant data (c) a constant pointer to nonconstant data (d) a constant pointer to constant data
A class may contain multiple constructors if (a) they have different names. (b) they have different argument lists. (c) they have the same argument list. (d) they have different return types.
Classes do not have the property of (a) encapsulating data. (b) information hiding. (c) containing both data and functions. (d) usually knowing how other classes are implemented.
Assuming that t is an array and tPtr is a pointer to that array, what expression refers to the address of the fourth element? (a) *( tPtr + 3 ) (b) tPtr[ 3 ] (c) &t[ 3 ] (d) *( t + 3 )
Which of the following is not true of a constructor and destructor of the same class? (a) they both have same name aside from the tilde (~) character. (b) they are both called once per object (in general). (c) they both are able to accept default arguments. (d) both are called automatically, even if not defined in the class.
Which of the following is not a valid way to pass arguments to a function in C++? (a) call-by-reference with reference arguments (b) call-by-value (c) call-by-reference with pointer arguments (d) call-by-value with pointer arguments
In the following program segment #ifndef X rest of program #endif (a) will evaluate the rest of the program if X is already defined. (b) will evaluate the rest of the program if X is not already defined. (c) will evaluate the rest of the program regardless of whether X is defined. (d) will cause a syntax error.
The get and set functions of a class (a) are implicitly defined in the class. (b) are private member functions. (c) cannot modify private data. (d) must be implemented by the programmer.
Member access specifiers (public and private) can appear (a) in any order and multiple times. (b) in any order (public first or private first) but not multiple times. (c) in any order and multiple times, if they have brackets separating each type. (d) outside a class definition.
Which of the following is false about a function being passed an array? (a) it knows the size of the array it was passed (b) it is passed the address of the first element in the array (c) it is able to modify the values stored in the array (d) the array name is passed as an argument
Which of the following operations does not produce a string? (a) char string1[] = “test”; (b) char string1[] = { ‘t’, ‘e’, ‘s’, ‘t’, ‘\0’ }; (c) char string1[] = { ‘t’, ‘e’, ‘s’, ‘t’ }; (d) char string1[] = “ ”;
Comparing pointers and performing arithmetic on them is meaningless unless (a) they point to members of the same array (b) you are trying to compare and perform arithmetic on the values to which they point (c) they point to arrays of equal size (d) they point to different locations
A default constructor (a) is a constructor with all default arguments (b) is the constructor generated by the compiler when one is not provided by the programmer (c) does not perform any initialization (d) both (b) and (c)
What value does function mystery return when called with a value of 4? int mystery ( int number ) { if ( number <= 1 ) return 1; else return number * mystery( number – 1 ); } (a) 1 (b) 24 (c) 0 (d) 4
True/False There should eventually be a call to the operator delete on a pointer that points to the memory allocated by each call to new.
True/False There should eventually be a call to the operator delete on a pointer that points to the memory allocated by each call to new. Answer: True Explanation: Pointer variables are usually local variables. Memory allocated on the free store using the new operator remains allocated whether you use it or even have a pointer pointing to it. If the pointer that points to the allocated memory dies with the end of a function or a block, the memory allocated is locked away so that no one can use it until the program terminates.
All of the following could cause a fatal execution-time error except (a) dereferencing a pointer that has not been assigned to point to a specific address (b) dereferencing a pointer that has not been initialized properly (c) dereferencing a 0 pointer (d) dereferencing a nonpointer
Classes cannot (a) be derived from other classes. (b) initialize data members in the class definition. (c) be used to model attributes and behaviors of objects. (d) include objects from other classes as members.
Which of the following is not a property of structs? (a) structs reserve space in memory when they are defined. (b) structs are built using elements of other data types. (c) Members of a struct must have unique names. (d) Structure variables are declared like other variables, except the structure name is used as the type.
Member function definitions • (a) always require the binary scope operator (::). • (b) only require the binary scope operator when being defined outside of the scope of • their class. • (c) can use the binary scope operator anywhere, but become public functions. • (d) must use the binary scope operator in their function prototype.
When a compiler encounters a function parameter for a single-subscripted array of the form int a[], it converts the parameter to (a) int a (b) int &a (c) int * a (d) int * const a
By default, class variables declared without an access modifier (a) can be modified by functions outside the class. (b) cannot be modified except by private functions of other classes. (c) can only be modified by private functions inside that class. (d) can be modified by any function inside that class or by friends of the class.
A recursive function is a function that (a) returns a double (b) takes 3 arguments (c) calls itself (d) is inside of another function
Given that k is an integer array starting at location 2000, kPtr is a pointer to k, and each integer is stored in 4 bytes of memory, what location does kPtr + 3 point to? (a) 2003 (b) 2006 (c) 2012 (d) 2024
The type of function a client would use to check the balance of his bank account would be (a) an access function. (b) a predicate function. (c) a utility function. (d) a constructor.
Which of the following can have a pointer as an operand? (a) ++ (b) *= (c) % (d) /
True/False The declaration below declares three pointer variables of type pointer to double that is, a pointer of type (double*)double* p1, p2, p3;
True/False The declaration below declares three pointer variables of type pointer to double that is, a pointer of type (double*)double* p1, p2, p3; Answer: False Explanation: This declares one pointer variable, p1, and two double variables, p2 and p3. The * binds more closely to the variable, not to the type. In spite of this, the usually style puts the asterisk against the type.
Pointers may be assigned to which of the following? (a) all integer values (b) an address (c) NULL (d) both (b) and (c)
Constructors are not (a) required to be explicitly defined. (b) called automatically when an object is initialized. (c) able to be overloaded. (d) member functions.
A pointer can not be assigned to (a) another pointer of the same type (b) a pointer to void (c) a pointer of a type other than its own type and void (d) any other pointer by using the cast operator