subject

You are provided with the following program poem. cpp. All is good, and the memory is allocated dynamically, but it crashes your computer, because it runs out of memory really quickly:

#include
using namespace std;

string * createAPoemDynamically() {
string *p = new string;
*p = "Roses are red, violets are blue";
return p;
}

int main() {
while(true) {
string *p;
p = createAPoemDynamically();

// assume that the poem p is not needed at this point

}
}
Fix this program poem. cpp. It should still keep creating poems, but all dynamically allocated memory should get deleted when it is not needed.

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 18:00
Martha is a healer, a healthcare provider, and an experienced nurse. she wants to share her daily experiences, as well as her 12 years of work knowledge, with people who may be interested in health and healing. which mode of internet communication can martha use?
Answers: 3
question
Computers and Technology, 23.06.2019 02:00
Arecipients list has been loaded into a document. which commands should be clicked in order to filter the list so that letters will not be printed for recipients who live in a certain state? mailings tab, start mail merge, select recipients, type new list, then insert only contacts from the desired states mailings tab, rules, select recipients, use existing list, then choose a recipients list that includes only contacts in certain states mailings tab, select recipients, use existing list, rules, fill in, then type in certain states mailings tab, rules, skip record select “state” under field name, then type in the state name under “equal to”
Answers: 2
question
Computers and Technology, 23.06.2019 09:30
The place where the extended axis of the earth would touch the celestial sphere is called the celestial
Answers: 1
question
Computers and Technology, 23.06.2019 15:00
Plz ( which is an example of a good url?
Answers: 1
You know the right answer?
You are provided with the following program poem. cpp. All is good, and the memory is allocated dyna...
Questions
question
Mathematics, 07.04.2020 19:56
question
Mathematics, 07.04.2020 19:56
Questions on the website: 13722367