Question
C ++ 1. Write down the missing code according to the comments. #include #include using namespace std; void fun1(int radius) { /* dynamic memory management
C ++
1. Write down the missing code according to the comments.
#include #include using namespace std;
void fun1(int radius) { /* dynamic memory management */ double * dmptr; double circumference;
/* add the code below to: - allocate a memory location for a double and nameless variable in heap and assign its address to the pointer - assign 3.14 to the variable in heap via the pointer. */
/* add the code below to: - calculate the circumference of a circle. Its radius is from the parameter of this function and the value of pi is from the nameless variable in heap */
/* print the area */ cout<<" circumference = "<< circumference < delete dmptr; } void fun2(int n) { int sum = 0; int *dmptr; /* add the code below to: allocate n memory locations for an integer and nameless array in heap via a pointer */ /* add the code below to: inializate the array in heap */ for(int i=0; i { dmptr[i] = i * 2; } /* calculate the sum of the elements of the array in heap */ /* print the sum */ cout<<"sum="< delete[] dmptr; } int main() { fun1(2); fun2(5); return 0; } |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started