Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 9.1, Problem 6STE
Suppose a dynamic variable were created as follows:
char *p; p = net* char; |
Assuming that the value of the pointer variable p has not changed (so it still points to the same dynamic variable), how can you destroy this new dynamic variable and return the memory it uses to the freestore so that the memory can be reused to create new dynamic variables?
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
In C Programming:
Write a function printCourseRow() which receives a course pointer and prints all its fields as a single row. Use proper formatting so that when we print 2 or more courses as rows, the same members align below each other. Test the function, but don’t include the testing code in your homework.Upload a screenshot of a sample output.
Write a C++ program that will implement and test the five functions described below that use pointers and dynamic memory allocation.
The Functions:
You will write the five functions described below. Then you will call them from the main function, to demonstrate their correctness.
findLast: takes an array of integers, its size and a target integer value. Returns an index of the last occurrence of the target element in the array. If the target value doesn't exist, returns -1. For this function only: Do not use square brackets anywhere in the function, not even the parameter list (use pointer notation instead).
nextFibonacci. Modify the following function to use pointers as parameters (instead of reference parameters). The Fibonacci sequence is a series of numbers where each number is the addition of the previous two numbers, starting with 0, and 1 (specifically: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55…). This function updates the given i-th and (i+1)-st Fibonacci numbers to (i+1)-st and…
Please give me correct solution.
Chapter 9 Solutions
Problem Solving with C++ (10th Edition)
Ch. 9.1 - Prob. 1STECh. 9.1 - Prob. 2STECh. 9.1 - Give at least two uses of the operator. State...Ch. 9.1 - Prob. 4STECh. 9.1 - Prob. 5STECh. 9.1 - Suppose a dynamic variable were created as...Ch. 9.1 - Write a definition for a type called NumberPtr...Ch. 9.1 - Prob. 8STECh. 9.2 - Write a type definition for pointer variables that...Ch. 9.2 - Suppose your program contains code to create a...
Ch. 9.2 - Prob. 11STECh. 9.2 - Prob. 12STECh. 9.2 - What is the output of the following code fragment?...Ch. 9.2 - What is the output of the following code fragment?...Ch. 9.2 - What is the output of the following code fragment?...Ch. 9 - Prob. 1PCh. 9 - Write a program that asks the user to input an...Ch. 9 - Palindrome testing with pointers This Practice...Ch. 9 - Do Programming Project 3 in Chapter 7 in this...Ch. 9 - Do Programming Project 11 in Chapter 7 using a...Ch. 9 - Write a function that takes a C string as an input...Ch. 9 - Prob. 5PPCh. 9 - One problem with dynamic arrays is that once the...Ch. 9 - Prob. 7PPCh. 9 - Write a program that outputs a histogram of...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Demonstrate each of the anomaly types with an example.
Modern Database Management
Write a simple assignment statement with one arithmetic operator in some language you know. For each component ...
Concepts Of Programming Languages
Give an example of a variable declaration that will store the name of your favorite food
Starting out with Visual C# (4th Edition)
Redefine the method getDataAtCurrent in StringLinkedListWith Iterator (Listing 12.9) so that it throws an excep...
Java: An Introduction to Problem Solving and Programming (8th Edition)
Suppose you have a chess program that can evaluate 10 million nodes per second. Decide on a compact representat...
Artificial Intelligence: A Modern Approach
List for advantages of SQL-invoked routines.
Modern Database Management (12th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Differences between void and NULL pointers are as follows: Provide relevant instances to back up your claim.arrow_forwardIn C++ Create an array of head pointers, statically allocated of size 101 of that type: Now, create a pointer that can point to the first element: Show how to dynamically allocate an array of 101 elements of head pointers: Write the code to initialize each element to NULL: Rewrite the code to initialize each element to NULL using pointer arithmetic:arrow_forwardProgramming 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_forward
- Need help with these assignments, I use C++. Thank you. Lab 4: Declare and implement a BSTNode ADT with a data attribute and two pointer attributes, one for the left child and the other for the right child. Implement the usual getters/setters for these attributes. Declare and implement a BST as a link-based ADT whose data will be Dollar objects - the data will be inserted based on the actual money value of your Dollar objects as a combination of the whole value and fractional value attributes. For the BST, implement the four traversal methods as well as methods for the usual search, insert, delete, print, count, isEmpty, empty operations and any other needed. Your pgm will use the following 20 Dollar objects to be created in the exact order in your main to seed the tree: $57.12 $23.44 $87.43 $68.99 $111.22 $44.55 $77.77 $18.36 $543.21 $20.21 $345.67 $36.18 $48.48 $101.00 $11.00 $21.00 $51.00 $1.00 $251.00 $151.00 Also, create an output file to write program output as specified…arrow_forwardAnswer the following as completely as possible in your own words:1. Explain how an array is sent to a function as a parameter.2. State which parameters should almost always be sent to any function which modifies an array. Explain why.3. Explain the similarity between index notation and pointer arithmetic.arrow_forwardCreate a type of Struct DynamicArray. This contains an int array You will use the type as a dynamic array. array inside dynamic array when the existing array is full and a new element needs to be added will double its size, make all the elements of the old array the same will copy the indexes and add the element to the new array. The following use functions with this type: 1.append(dynamic array, new element): Function sent to itself Adds the element struct to the end of the array inside DynamicArray. Place If not, it behaves in accordance with the dynamic array definition given above. 2.get(index): The element in the index sent to it by the function takes it from the array it hosts and sends it back. 3. Try struct DynamicArray in a main function. Solve the question in C language?arrow_forward
- write a program in c++ which contains two functions: 1. declare a dynamic array and write resize functions which resizes array in such a way that it retains old data and discard overflow data if new size is smaller. 2.declare a dynamic matrix and write resize functions which resizes matriz in such a way that it retains old data and discard overflow data if new size is smallerarrow_forwardC++ LANGUAGE In this assignment, you will be writing two objects to heuristically compare the performance of the bubble sort, selection sort, and insertion sort algorithms. To do this, a “Timer” object will be created and compositionally related to a storage class that will load the file contents, execute the sorts in an unbiased manner, handle any memory allocations that need to be made in order to do this, and reports back the execution times of each algorithm on the provided input files for that machine. First you will need to make a Timer object. This object should function like a traditional stopwatch with methods for starting, stopping, resetting, and reporting back times. The design of the object itself is up to you (it should minimally contain methods for the aforementioned ideas), but it must consist of a solitary object that provides interfaces appropriate for being compositionally included as part of a sorting object to facilitate the timekeeping portion of this exercise.…arrow_forwardvoid change_current_directory(char *directory) {} This is to be done in Carrow_forward
- The distinction between void and NULL pointers is as follows: Make use of appropriate examples to support your response.arrow_forwardin C++... kth Element Extend the class linkedListType by adding the following operations:a. Write a function that returns the info of the kth element of the linked list. If no such element exists, terminate the program.b. Write a function that deletes the kth element of the linked list. If no such element exists, terminate the program. Provide the definitions of these functions in the class linkedListType. PLEASE DON'T reject this question, this is the whole question that I have... so please do it however u can, Thank you!arrow_forwardAn array is a container object that holds a fixed number of values of a single type. To create an array in C, we can do int arr[n];. Here, arr, is a variable array which holds up to integers. The above array is a static array that has memory allocated at compile time. A dynamic array can be created in C, using the malloc function and the memory is allocated on the heap at runtime. To create an integer array, of size , int *arr = (int*)malloc(n * sizeof(int)), where points to the base address of the array. When you have finished with the array, use free(arr) to deallocate the memory. In this challenge, create an array of size dynamically, and read the values from stdin. Iterate the array calculating the sum of all elements. Print the sum and free the memory where the array is stored. While it is true that you can sum the elements as they are read, without first storing them to an array, but you will not get the experience working with an array. Efficiency will be required later.…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Instruction Format (With reference to address); Author: ChiragBhalodia;https://www.youtube.com/watch?v=lNdy8HREvgo;License: Standard YouTube License, CC-BY