Computer Science 3rd Lecture Exam Reading Quizzes

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

True

A Struct can have a Pointer as a member. True or False?

pointer

A _______ is a special variable that holds a memory address. (one word)

C-string

A ________ is a string whose characters are stored in consecutive memory locations and are followed by a null character, or null terminator.

values

A data type defines what ______ a variable may hold.

True

A pointer may be subtracted from another pointer. True or False?

exception

A program signals that a problem has occured by throwing an _________.

enumerated data type

A programmer-defined data type for which all the allowed values are specified is known as an _________ ____ ____.

nullptr

After using delete on a pointer to release the memory. It is good practice to set it equal to _______.

instance

An ________ of a structure is a variable that exists in memory

concatenation

Appending one string to another string is called _____________.

constants

Array names are point _________.

A

As collections, Arrays are limited because they... A) Can only hold data of the same type B) Have the means to index their data C) Can only hold data in a particular order D) Contain pointers to the location of their first piece of data

False

Because of the amount of memory a Struct holds can vary and is unknowable at runtime, it is impossible to dynamically allocate memory to a struct. True or False

3

C++ 11 provides how many different types of smart pointer? (Enter a number)

False

C-strings are a newer development in C++. In older versions of the language, only strings were allowed. True or false?

Yes

Can a struct be used as the data type for a member of another struct? Yes or No?

ios::in

Data will be read from the file. If the file does not exist, it will not be created and the open function fails.

ios::out

Data will be written to the file. Content will be deleted if it already exists.

ends

Dynamically allocated memory will remain allocated until the delete operator is used or the program ____.

True

Enumerators are given ascending positive integer values by default, but the programmer give the enumerators any other arbitrary integer value if they like. True or False?

leak

Failing to release dynamically allocated memory can cause a program to have a memory ____.

C, D

Given int nums[] = {5, 4, 3, 2, 1}; int* ptr = nums; Which of the following are true? (Can be multiple answers. Answer in the format of A, B, C, D in alphabetical order) A) *(ptr + 4) > *(ptr); B) &nums[0] > &nums[4]; C) ptr + 4 > ptr; D) nums[0] > nums[4];

True

Given string name1 = "George"; char name2[] = "Sally"; name1.size() = sizeof(name2); True or False?

True

Given string name1 = "Simon"; string name2 = "Quiet"; name1.length() == name2.size(); True or False?

False

Given: char letter = 'A'; cout << tolower(letter) << endl; evaluate: (letter == 'a') True or false?

(*cirPtr).radius

How do you correctly access the member of the Circle struct without using the -> operator? struct Circle { double radius; }; Circle* cirPtr = nullptr;

2

How many arguments does the fstream open() function take?

7

How many characters are reserved in the following char array: char name = "Melody"; Hint: The null terminator (;) counts as a character.

ios::app

If the file exists, its contents are preserved and all output is written at the end of the file.

ios::ate

If the file exists, the program goes to the very end of it. Output may be written anywhere in the file.

cast

If you must store an integer into an enum variable, you can do so as long as you ____ it first.

smart pointers

In C++ 11, you can use _____ ________ to dynamically allocate memory without worrying about needing to delete it when you are done using it.

token

In a string or stream of data that can be divided into chunks (example: "Apples Bananas Oranges Grapes". each chunk is called a _____.

False

In order to print the members and their values of a structure, you pass the name of the structure variable to cout. True or False?

cctype

In order to use CST functions such as isalpha() or ispunch() or toupper(). you need to include the <______> header file.

abstraction

In the following examples: int x = 3; int y = 5; int x = 7; The data type, int, is an example of an ____________, where as the variables x, y, and z are concrete concerences.

B

In the given expression, you know that a is... (answer would be formatted like A,B,C,D) ( * s).a // Pretend the spaces in the () aren't there. A) structure B) member C) pointer D) nothing

B,C

In the given expression, you know that a is... (answer would be formatted like A,B,C,D) *(*s).a A) structure B) member C) pointer D) nothing

B,C

In the given expression, you know that a is... (answer would be formatted like A,B,C,D) *s->a A) structure B) member C) pointer D) nothing

B,C

In the given expression, you know that a is... (answer would be formatted like A,B,C,D) *s.a A) structure B) member C) pointer D) nothing

B

In the given expression, you know that a is... (answer would be formatted like A,B,C,D) s->a A) structure B) member C) pointer D) nothing

D, A, B, C

Match the following expressions to their descriptions (answer would be formatted like A,B,C,D): ( ) const int* ptr = &x; ( ) const int* const ptr = &x; ( ) int* const ptr = &x; ( ) int* const ptr = const &x; A. a constant pointer to a constant int B. a constant pointer to an int C. nonsense D. a pointer to a constant int. Hint: The first data type correlates to x and the second correlates to the pointer.

constant reference

One can get around the potential problems of passing a struct by reference by passing it as a ________ _________.

True

One way to get around the limitation of only being able to return a single value from a function is to bundle several pieces of information into a struct. True or False

tellg

Returns the current read location in number of bytes from the beginning.

False

Structures, unlike other variables, are normally passed by reference into a function. True or False?

indirection

The * in line 3 is called the ___________ operator. 1. int num = 25; 2. int* ptr = &num; 3. cout << *ptr << endl;

find

The ____() function searches for a string inside another one.

False

The following struct PayRoll { int empNumber; string name; double hours, payRate, grossPay; }; creates a variable of the PayRoll type. True or False?

False

The following code will compile: const int SIZE = 5; const double payRates[SIZE] = {18.50, 17.28, 20.00, 10.00, 14.25}; displayPayRates(payRates, SIZE); void displayPayRates(double* rates, int size) { for (int i = 0; i < size; i++) { cout << rates[i] << endl; } } True or False?

False

The following code will return a pointer to an array storing the users name? string* getFullName() { string fullname[3]; cout << "Enter your first name: "; getline(cin.fullName[0]); cout << "Enter your middle name: "; getline(cin.fullName[1]); cout << "Enter you last name: "; getline(cin.fullName[2]); return fullName; } True or False?

reference

The following function header contains a _________ variable void getOrder (int &donuts);

44

The following statement will accept input until the __ (st/nd/rd/th) character is entered or the enter-key is pressed. const int SIZE = 45; char line[SIZE]; cin.getline(line, SIZE);

False

The following will cause an error: enum class days { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY }; enum class weekDays { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY }; True or False

True

The following will cause an error: enum days { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY }; enum weekDays { MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY }; True or False?

True

The following will initialize an array of PayInfo structs: struct PayInfo { int hours; double payRate; } PayInfo workers[3] = { { 10, 9.75 }, { 15, 8.62 }, { 40, 15.65 } }; True or False?

atoi

The function in the cstdlib header that turns a C-string into an int for processing is the ____ function.

D

The integer value of which of the following types of enums can be retrieved without a cast? A) weakly-typed enum B) strongly-typed enum C) focused enum D) enum

enumerators

The permitted (and specified) values of an enum are known as __________.

True

The strcpy function performs no bounds checking on the first argument.

False

The strlen function return the size of the array containing a string. True or False?

->

The symbol called the structure pointer operator is __.

ofstream

This data type can be used only to create files and write data to them

ifstream

This data type can be used only to read data from files into memory.

fstream

This data type can be used to create files, write data to files, and read data from them.

int

This data type can store whole number values.

True

This is a legitimate function: void tripleNumbers(int* num) { *num *= 3; } && This is how you would call it: int value = 7; tripleNumber(&value) True or False?

dot operator

To access the members of a structure, use the ___ ________

False

To initialize an array of structs, you must first create the array, and then process the array item by item to populate it. True or False?

True

We can declare a pointer in the following ways: int* ptr = nullptr; int * ptr = nullptr; int *ptr = null ptr; True or False?

&number

What expression would get the address of the following variable: int number = 9;

3412

What is the value of number given the following? char nums1[8] = "12"; char nums2[8] = "34"; strcat(nums2, nums1); int number = stoi(nums2); (NOT MULTIPLICATION)

new

What operator is used to allocate memory dynamically?

75

What will be printed to the console? int numbers[] = {25, 50, 75, 100}; cout << *(numbers + 2) << endl; Hint: Look at where the paratheses and * operator is.

28

What will be printed to the console? int numbers[] = {25, 50, 75, 100}; cout << *numbers + 3 << endl; Hint: Look at where the * operator is - Does no parentheses mean anything?

25

What will be printed to the console? int numbers[] = {25, 50, 75, 100}; cout << *numbers << endl; Hint: Look at where the * operator is

address

When a computer allocates memory dynamically, it sets aside memory of a particular size. That memory can only be accessed by its _______.

dynamic memory allocation

When a program, while running, asks the computer to set aside a chunk of unused memory large enough to hold a variable of a specific data type. It is called _______ ______ __________.

memory address

When a string literal appears in a statement, it's actually the ______ _______ that C++ uses.

delimiter

When a string or stream of data is divided into chunks, the character or characters that is used to designate where the division should occur is a _____________.

members

When a struct is declared, the variable declarations inside the braces declare _______ of the structure.

anonymous

When an enum is created without a name, it is an _________ enumerated type.

dereferences

When the * comes before a pointer variable, it ____________ the pointer.

ios::binary

When the file is opened, data is written to it or read from it in pure binary instead of text.

B, C, D, F

Which of the following are correct initializations of int*ptr? (Can be multiple answers. Answer in the format of A, B, C, D in alphabetical order) A) int* ptr = num; int num; B) int num; int* ptr = &num C) double speeds[75], *ptr speeds; D) int nums[20]; int* ptr = nums; F) int num, *ptr = &num; G) double speed; int* ptr = &speed;

A, C

Which of the following are legitimate initializations for the struct (answer would be formatted like A,B,C,D): struct Employee { string name; double salary; Data birthdate; int ID; string title; }; A) Employee sam = {"Sam", 4000, {12, 12, 2001}, 132, "Substitute"} B) Employee sam = {"Sam", {12, 12, 2001}, 4000, 132, "Substitute"} C) Employee sam = {"Sam", 4000} D) Employee sam = {"Sam", 4000, , , "Substitute"}

B

Which of the following is the appropriate way to refer to a strongly-typed enumerator? A) <Presidents>MCKINLEY B) Presidents::MCKINLEY C) Presidents->MCKINLEY D) Presidents.MCKINLEY

D

Which of the following will NOT work as an argument for a C-string handling function, such as strlen()? (answer would be formatted like A,B,C,D) A) The name of the array holding the C-String B) A pointer variable that holds the address of the C-String C) A literal string D) A string variable name

B,C

Which of the following will correctly access the member of the Circle struct? (answer would be formatted like A,B,C,D) struct Circle { double radius; }; Circle* cirPtr = nullptr; A) *cirPtr.radius B) (*cirPtr).radius C) cirPtr->radius D) (*cirPtr.radius)

A,B,C

Which of the following will work as an argument for a C-string handling function, such as strlen()? (answer would be formatted like A,B,C,D) A) The name of the array holding the C-String B) A pointer variable that holds the address of the C-String C) A literal string D) A string variable name

C

Why is the advantage of passing a struct by reference to a function rather than by value? (answer would be formatted like A,B,C,D) A) Doing so generates less revenue, but more name recognition. B) You don't have to worry about corrupting the version of the struct in the calling function. C) The program can be more performant because a copy of a structure does not have to be made. D) You can not access the original struct.

True

You can use enumerators as array subscripts. Example: avgTemp[JANUARY] True or False

True

You cannot compare struct variables by setting them equal to each other. e.g. Employee sam; Employee dolly; if (sam == dolly) delete(dolly); // duplicate entry True or False?

False

double speed; int* ptr = &speed; This is a correct initialization of int* ptr; True or False?

True

double speeds[75], *ptr speeds; This is a correct initialization of int* ptr; True or False?

z

given string sleeping('z', 10); what is the value of sleeping[4]?

True

int num, *ptr = &num; This is a correct initialization of int* ptr; True or False?

True

int num; int* ptr = &num This is a correct initialization of int* ptr; True or False?

True

int nums[20]; int* ptr = nums; This is a correct initialization of int* ptr; True or False?

False

int* ptr = num; int num; This is a correct initialization of int* ptr; True or False?


संबंधित स्टडी सेट्स

GS MKT 306 CH 4 - Consumer Behavior

View Set

C: Criminal Evidence and Procedure

View Set

Chapter 25: HAZMAT Action Options and Response Objectives

View Set

Chapter 10. The Presidency | Housel's Guide

View Set

24. Immunizations -- Pneumococcal Vaccines

View Set

Chapter 5, Land forms and Resources US and Canada

View Set

AD Banker: NJ Life Comprehensive

View Set

901 practice test hardware troubleshooting

View Set