1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
velikii [3]
3 years ago
10

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.
Computers and Technology
1 answer:
Maslowich3 years ago
8 0

Answer:

See explaination

Explanation:

#include <iostream>

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();

if (!p)

{

cout << "Memory allocation failed\n";

}

cout<<*p<<"\n";

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

//delete allocated memory

delete p;

}

}

You might be interested in
In a black box model are the customers told that they should be expecting to be haxked?
Licemer1 [7]
Uhhhhhhhhhhh maybe tbh i have noooo idea.
6 0
3 years ago
The condition known as __________ occurs when you try to store an integer that is bigger than the maximum allowed by the number
Gnoma [55]

The condition known as <u>overflow</u> occurs when you try to store an integer that is bigger than the maximum allowed by the number of bits you have.

<h3>What is a buffer?</h3>

In Computer science, a buffer can be defined as a temporary area set aside on a computer system for the storage of data. This ultimately implies that, a buffer reside in the random access memory (RAM) of a computer system.

In the event that a computer system process or software program places more data (much more than what was originally intended to be allocated for data storage) in a buffer, the extra data overflows.

In this context, we can infer and logically deduce that when a value is assigned to an integer that is too big or large for the computer to represent, it is a condition referred to as an overflow.

Read more on overflow here: brainly.com/question/26143242

#SPJ1

4 0
1 year ago
How do i know when someone answered my questions and where can i check what they wrote?
maksim [4K]

Answer:

U can go to your profile, then go to your question to see what they have written.

Explanation: Hope this helps

3 0
3 years ago
50 points! ㅠㅠ does anyone speak korean or watch korean animes? 안녕 ㅋㅋ ㅇㅅㅇ How do people make animationsss.
aleksklad [387]

Answer:

Explanation Well depends on what type of animations your asking for but Anime is almost entirely drawn by hand but It also takes skill to create hand-drawn animation and experience to do it quickly. ... They're the ones who make all the individual drawings after the top-level directors come up with the storyboards and the middle-tier “key animators” draw the important frames in each scene it has a lot of process .

6 0
3 years ago
Read 2 more answers
What is the first structure of a pascal program?
lapo4ka [179]

A Pascal program basically consists of the following parts :

Program name, uses command, type declarations, constant declarations, variables declarations, functions declarations, procedures declarations, main program block, statements and Expressions within each block, and comments

6 0
3 years ago
Other questions:
  • _ includes websites that encourage interaction and connection among people, businesses, and organizations.
    5·1 answer
  • What sugar is used in a DNA molecule​
    7·2 answers
  • Design an algorithm for finding all the factors of a positive integer. For example, in the case of the integer 12, your algorith
    8·1 answer
  • Why is it important for software developers to study Human-Computer Interaction? to make sure a user interface is easy to use, w
    10·2 answers
  • Give 2 examples of when spreadsheets are used.
    15·1 answer
  • Which segment of society introduced the grunge look?
    5·2 answers
  • Write a function in Java that implements the following logic: Given a string and an int n, return a string made of n repetitions
    15·1 answer
  • What outline feature can the Navigation pane browse the document by?
    14·2 answers
  • The HTTP protocol operates at which layer?
    7·1 answer
  • Will give brainly if answer all or my questions
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!