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

Create a function that (1) receives an integer argument that specifies the size

ID: 3862576 • Letter: C

Question

Create a function that (1) receives an integer argument that specifies the size of the array (2) creates a char array on the heap of that size (3) returns that char array to the user: Create a void function that will take a char array as input, and will free all of its memory on the heap and set it to NULL after freeing memory. Which of the following correctly declares a dynamic 2d array of size x * y on the heap? Justify why the others are incorrect. a) int** p = new int[x][y]; b) int** p = new int*[x]; for

Explanation / Answer

#include <iostream>
#include <conio.h>
using namespace std;

char* charArray(char* message, int length);

int main()
{
   // lenth of the char array
const int len = 10;
// declaring message
char message[len];

// calling charArray fucntion
cout << charArray(message, len) << endl;
   //getch();
return 0;
}

char* charArray(char* message, int length)
{
for(int i = 0; i < length; i++)
{
message[i] = 'a';
}
return message;
}

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