COP3014 Milestone 3 All TopHat Questions (Chapters 12-15)

Ace your homework & exams now with Quizwiz!

123480

"ptr" is a pointer to a double. A double variable occupies 8 bytes in memory. If the current value in "ptr" were 123456, what is the value in ptr after the following line (please use decimal values instead of hex for your math) ptr = ptr + 3;

address (memory address, byte address)

A pointer is a variable that can hold the ___________ of another variable of the same type

a

A single struct variable would pass by A value B reference C address

a (t)

An internal variable in a struct could involve dynamic memory a True b False

append

An output file opened in __________ mode will add to the current file contents instead of deleting the contents upon opneing the file.

(Create a pointer of the required type Use the new operator to allocate memory and store the address in the pointer Dereference the pointer to use the value Use the delete operator to clear the allocated space)

Arrange the following in the order of operations required to use a dynamically allocated variable

c

Consider the following function declaration: int count (char *st) If you had a for loop (loop variable i) iterating through the C-String st in the function, which of the following lines would result in an error? (a) cout<<st[i]; (b) st[i++] = 'X'; (c) cout<<*st[i]; (d) cout<<*(++st);

14047

Consider the struct Employee. It has 4 data members - a cstring of size 30, an integer, a double, and a char. An array of Employee structs begins at the address 12800. What is the address of element 29 of the array?

72

How many bytes of space is occupied by 1 variable (object) of the following struct? struct Item {char itemID​​​[10]; int quantity; double price; char name​​​[50]; };

d

If we pass a dynamic array by address, which of the following is FALSE? a 2 functions will have 2 pointers (1 each) pointing at the same area of memory b If we dereference the pointer in the function and make changes to dynamic data, the changes will persist when we return to the calling function c The pointer created in the function is local to the function and will be destroyed when we return from the function d Since the link from the called function to the dynamic memory is destroyed upon return, the dynamic memory is deallocated.

(x++ - x=x+1; arr​[i] - *(arr+i); structPtr->inside - *(structPtr).inside; !(x>0) - x<=0)

Match the equivalent operators. You may assume all the variables (with compatible types) have been declared and initialized correctly.

(Input - ifstream; output - ofstream)

Match the file stream with its purpose

(Binary File - Stores the values as they would be stored in memory (in machine readable form); Text File - Stores all values as strings (human readable form))

Match the file type with their descriptions

(Pass by Value - int function(int x); Pass by reference - int function(int &x); Pass by address - int function(int *x);)

Match the function prototype with the method of passing

(Create the file objects (variables of type ifstream or ofstream) Open the files and check if they have been opened correctly Perform the I/O operations using the file objects instead of cin/cout Close the files)

Order the following in the sequence of steps required to properly perform File I/O in C++.

b (f)

Passing a dynamic 2-dimensiponal array into a function requires the number of columns a True b False

a (t)

Pointer arithmetic is always done in units of the type size (any addition or subtraction of a value 'x' from a pointer will actually add or subtract x * type size) a true b false

c

Pointers are essentially numbers. What C++ primitive data type is the "closest match" to a pointer in terms of the values being stored on a contemporary machine? a int b float c long d double

reference

Stream objects will always pass by _________

b

Text files must be saved with a ".txt" extension for C++ to open and interact with them. a True b False

7

Text files store data as strings, with each character occupying a byte of space. Binary files store values the same way the data would be stored in memory. The integer value 1234567 will occupy 4 bytes in a binary file. How many bytes would it occupy in a text file?

b

The internal variables of a struct can only be accessed in the order they were specified in the declaration a True b False

a (t)

The name of an array is a pointer to the starting address of the array a True b False

dereference

To get the value in a dynamic variable, we have to ___________ the pointer that stores its address

reference

Unless specified otherwise, a stream object will always pass by ____________

value

Unless specified otherwise, a struct object (variable) passes by ________

a (t)

Variables declared in the heap are unnamed and may only be accessed through a pointer Select an answer and submit. a True b False

a (t)

We can access the same chunk of dynamic memory from different functions as long as we have a pointer to that memory chunk. a True b False

cout<<cop3014.roster​​[0].dateOfBirth.year;

We have a "Course" struct that constants an array, called "roster", of 20 "Student" struct variables. Each student struct contains a Date struct variable called "dateOfBirth". Each Date variables contains 3 integers, called "Month", "day", and "year". If the main function contains a single Course struct variable, called "cop3014", how would you print the year of Birth of the 0th student in the Course variable? Please do not use extra spaces in your line of code

57

We have a Grade structure, which consists of the following elements: AssignmentName: c-string of 45 characters PossiblePoints: integer ReceivedPoints: double If a char occupies 1 byte, an int occupies 4 bytes, and a double occupies 8 bytes, what is the size (in bytes) of one object of the Grade sturcture?

-1.3 3.8 0.7

What is the output of the following code snippet?

-4.35 -0.35 -3.9

What is the output of the following code snippet?

0

What is the output of the following code snippet?

17.45

What is the output of the following code snippet?

25.8

What is the output of the following code snippet?

4667

What is the output of the following code snippet? ​

b

What is the output of this code snippet? a Address of x b 25 c address of ptr d Cannot be determined

double *

What is the return type of a function that can return an array of doubles?

32

What is the size (in bytes) of this struct? struct Item { char name[20]; double price; int quantity; };

ifstream

Which class is the "data type" for a file object used to perform input

reference

Which is the default passing method for an array of structs?

fstream

Which library must be included to perform I/O operations from files?

d

Which of the following is NOT a valid R-value to a pointer to an integer variable? a ptr (another pointer to the integer) b nullptr c reinterpret cast into an integer pointer d 0xFFFF04C84C

d

Which of the following is NOT allowed in a struct declaration? a Having an array as an internal element b Having variables of 2 different data types as internal elements c Having another struct object as an internal element d Giving values to internal elements

b

Which of the following is TRUE about pass by address? a Pass by address copies the value of the actual parameter into the formal parameter b Pass by address requires dereferencing to change the value of the parameter c Changing the value in the function doesn't affect the parameter in the calling function d Passing by address does not use pointers

d

Which of the following is a C++ reserved word? (a) file (b) ifstream (c) ofstream (d) struct

c

Which of the following is the "type" for a file object that can be used to read from an input file? a iostream b fstream c ifstream d ofstream

b

Which of the following operators is defined for struct variables? a + b = c <= d /

c

Which of the following passing methods requires a pointer? a Pass by value b Pass by reference c Pass by address d all of the above

c

Which of the following should NOT use the const qualifier? a search function that accepts an array as a pointer b A c-string literal c A swap function that modifies the values through the pointer d All of the above

d

Which of the following strings will be placed before "banana" in lexicographical order? (a) Peach (b) Strawberry (c) 2 green apples (d) All of the above

b

Which of the two techniques to read in a character is capable of capturing whitespace characters? a The extraction operator >> b The get() function c Both of the above are capable d None of the above are capable

a

Which of these is NOT a C++ keyword AND operator? a reinterpret_cast b sizeof c new d delete

d

Which of these is not a composite data type? a a struct variable of "Student" type b a c-string of 15 characters c an array of 10 doubles d a boolean variable

delete ​[] numbers;

Write a line of code that would delete a dynamic array caled "numbers"

heap (dynamic), leak

Dynamic Memory is declared in the _________ space and must be managed by the programmer. If we do not delete dynamic memory after use, it would result in a memory _____________


Related study sets

International Management Chapter 2

View Set

P&C CH.5 AUTO POLICY EXAM REVIEW

View Set

Ch. 2 The Nurse's Role in Healthcare Quality and Patient Safety

View Set

Policy Provisions, Options and Riders

View Set

MIE 330 Ch 4: The analysis and design of work

View Set

Spanish 2: Que, Lo Que, Quien, Quienes

View Set

Privacy of Consumer Financial Information

View Set