Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am having trouble understanding these problems. For each question can you please explain how you came up with your solution? Question 1: How many

I am having trouble understanding these problems. For each question can you please explain how you came up with your solution?

Question 1: How many times do you need to "delete" memory to prevent this code from leaking?

float *myData[3];

float *myPtr = nullptr;

for(int i = 0; i < 2; i++)

myData[i] = new float [10];

myData[2] = new float;

myPtr = myData[2];

a) 16

b) 4

c) 13

d) 12

e) 3

Question 2: How many times do you need to "delete" memory to prevent this code from leaking?

float *myData[3];

float *myPtr = nullptr;

for(int i = 0; i < 2; i++)

myData[i] = new float [10];

myData[2] = new float;

myPtr = myData[2];

a) 16

b) 4

c) 13

d) 12

e) 3

Question 3: What is one line of preprocessor directive that you can write to guard against code in a header file being defined more than once?

Question 4: Which is not a valid scope?

a) Pointer

b) Global

c) Brace

d) Function

e) Namepace

f) class

Question 5:

Given a class:

MyClass

And the following function:

void TestFunction(MyClass mc) { /*irrelevant code omitted*/}

Which member function of MyClass will be called as a result of, but not necessarily on, the following line:

Test(someExcistingMyClassObject);

a) Copy Constructor

b) Assignment Operator

c) Destructor

d) Constructor

Question 6: What will the code print out:

void AddPrimes(vector list) {

list.push_back(3);

list.push_back(5);

list.push_back(7);

list.push_back(11);

list.push_back(13);

}

vector primes;

primes.push_back(2);

AddPrimes(primes);

for(unsigned int i = 0;

i < primes.size(); i++) {

cout << primes[i];

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Datalog Engines In Databases

Authors: Bas Ketsman ,Paraschos Koutris

1st Edition

1638280428, 978-1638280422

More Books

Students also viewed these Databases questions