Write a function that dynamically allocates a block of memory and returns a char pointer to the block. The function should take an integer argument that is the amount of memory to be allocated. If the new operator cannot allocate the memory, the function should return a null pointer.
Want to see the full answer?
Check out a sample textbook solutionChapter 16 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Additional Engineering Textbook Solutions
Introduction To Programming Using Visual Basic (11th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
- In this assignment you are to use pointers to manipulate dynamically created arrays. An array's name is basically a pointer to the fisrt element of the array. Dynamic arrays are created using pointer syntax, but can subsequently use array syntax, which is the best practice approach. Instructions (main.cpp) Inside main.cpp implement the following functions: int makeArray (const int size); This function dynamically allocates an int array of the specified size. • size the size of the dynamically allocated array. • returns - a dynamically allocated integer array of size elements. void initializeArray (int * array, const int size, const int initValue); This function initializes an array of size elements with the initValue. array The array whose elements are to be initialized. size the size of the array. initValue the value with which to initialize each element. int duplicateArray (const int const sourceArray, const int size); This function duplicates an array of size elements. When copying…arrow_forwardIn C Programming: Write a function inputAllCourses() which receives an array of course pointers and the array’s size, then allows the user to input all courses in the array by calling inputCourse()arrow_forwardIN C PROGRAMMING LANGUAGE: Please write a pointer version of squeeze() named psqueeze(char *s, char c) which removes c from the string s.arrow_forward
- Programming language: C++ Implement a function named insert that takes a dynamically allocated array of ints, the array’s length, the index at which a new value should be inserted, and the new value that should be inserted. The function should allocate a new array populated with the contents of the original array plus the new value inserted at the given index. The originally array should be freed. The following sections provide a detailed description of this function: Make sure your source code is well-commented, consistently formatted, uses no magic numbers/values, follows programming best-practices, and is ANSI-compliant. It is expected to have the program outputarrow_forwardC Program Functions and Pointers Create a function called terminate that asks: integer array to be referenced for modification integer value to serve as an indexing variable. This function sets the value of an element in the array to 0 based on the index value provided. This function does not return anything. In the main function, write a program that asks the user for an integer input and call the terminate function by passing the array and the inputted integer. Print the contents of the modified array where each elements are separated by a space. Input 1. One line containing an integer input Output Ten int outputs each separated by a space Enter·a·number(0-9):·1 1·0·1·1·1·1·1·1·1·1 Create a function called terminate that asks: integer array to be referenced for modification integer value to serve as an indexing variable. This function sets the value of an element in the array to 0 based on the index value provided. This function does not return anything.…arrow_forwardWrite a function dispense_bills(). The function determines the minimum number of bills to dispense given a withdrawal amount. The possible bills dispensed include: 50’s, 20’s, and 10’s. The number of each bill to dispense should be stored indirectly through the pointers: fifties_ptr, twenties_ptr, and tens_ptr. If the withdrawal_amount exceeds the balance, then the number of each bill to dispense should be set to 0, and 0 should be returned. If the withdrawal_amount is less than or equal to the balance, then the number of each bill to dispense should be calculated, and 1 should be returned. The function header has been provided for you. // precondition: withdrawal amount must be a multiple of 10 // return: 1 if the balance >= withdrawal_amount; 0 otherwise int dispense_bills(double balance, double withdrawal_amount, int *fifties_ptr, int *twenties_ptr, int *tens_ptr) { }arrow_forward
- in c++ In statistics, the mode of a set of values is the value that occurs most often or with the greatest frequency. Write a function that accepts as arguments the following: A) An array of integers B) An integer that indicates the number of elements in the array The function should determine the mode of the array. That is, it should determine which value in the array occurs most often. The mode is the value the function should return. If the array has no mode (none of the values occur more than once), the function should return −1. (Assume the array will always contain nonnegative values.) Demonstrate your pointer prowess by using pointer notation instead of array notation in this function.arrow_forwardWrite the function definition for a value returning function that receives an array of integer values, the array length, and an integer target value as parameters. The function should perform a li ear (sequencial) search for the target value. If the value is found, the function should return the index position of the target value, otherwise, it should return -1. Write only the function definition.arrow_forwardProgramming in Carrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning