Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1st C++ Program: Container *ptr; ptr = new Container[2500]; 1. Suppose Container

ID: 3883140 • Letter: 1

Question

1st C++ Program:

Container *ptr;

ptr = new Container[2500];

1. Suppose Container is a C++ class. Which of the following is true?

a. an exception is thrown if the system does not have a memory of 2500 Container’s

b. the variable ptr points to an array of 2500 Container’s

c. the default constructor for Container is called 2500 times

d. all of them above

2. Suppose that the Container class does not have a default constructor. What would happen?

a. An exception will be thrown when the program reaches the second line.

b. The program will not compile.

c. When the program is executed, each Container object in the array would be initialized to all zeroes.

d. When the program is executed, the alternated contractor for Container will be called for each Container object in the array.

2nd C++ program:

int x, y;

int *ptr =&x;

ptr++;

Suppose that in the program above, the local variable x is stored in address 4294946208. If the sizeof(int) is 4, what is the value of the pointer ptr after execution of the program fragment?

a. 4294946212

b. 4294946204

c. 4294946209

d. the value of ptr cannot be determined from the information given.

Explanation / Answer

1. Suppose Container is a C++ class. Which of the following is true?

Ans: d. all of them above

2. Suppose that the Container class does not have a default constructor. What would happen?

Ans:c. When the program is executed, each Container object in the array would be initialized to all zeroes.

3. Suppose that in the program above, the local variable x is stored in address 4294946208. If the sizeof(int) is 4, what is the value of the pointer ptr after execution of the program fragment?

Ans: d. the value of ptr cannot be determined from the information given.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote