Starting Out with C++ from Control Structures to Objects (9th Edition)
9th Edition
ISBN: 9780134498379
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 9.9, Problem 9.13CP
Assume ip is a pointer to an int. Write a statement that will dynamically allocate an integer variable and store its address in ip. Write a statement that will free the memory allocated in the statement you wrote above.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Pointer Arithmetic
Write a program that accepts a string and print the reversed form of that string using a pointer ptr.
Input: One line Containing String
Sample Output:
Enter a string: Test
tseT
question
Write a c++ program that follows the program requirements below
IN JAVA OR C++ you will simulate a simple multithreading application with a “producer and consumer” problem
Modify “Producer and Consumer Problem” from the lecture note so that it can use all buffer space, not “buffersize – 1” as in the lecture note. This program should work as follows: 1. The user will run the program and will enter two numbers on the command line.Those numbers will be used for buffersize and counter limit.2. The main program will then create separate producer and consumer threads.3. The Producer thread generates a random number through a random number generator function, inserts it into the buffer, prints the number, and increment counter.4. The Consumer thread goes to the buffer, takes a number in the proper order, prints it out, and increment counter.5. After the counter reaches its limit, both threads should be terminated and returned to the main.6. Main program terminates.
Chapter 9 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Ch. 9.5 - Prob. 9.1CPCh. 9.5 - Write the definition statement for a variable...Ch. 9.5 - List three uses of the symbol in C++.Ch. 9.5 - What is the output of the following code? int x =...Ch. 9.5 - Rewrite the following loop so it uses pointer...Ch. 9.5 - Prob. 9.6CPCh. 9.5 - Prob. 9.7CPCh. 9.5 - Is each of the following definitions valid or...Ch. 9.9 - Prob. 9.9CPCh. 9.9 - Give an example of the proper way to call the...
Ch. 9.9 - Complete the following program skeleton. When...Ch. 9.9 - Look at the following array definition: const int...Ch. 9.9 - Assume ip is a pointer to an int. Write a...Ch. 9.9 - Prob. 9.14CPCh. 9.9 - Prob. 9.15CPCh. 9.9 - Prob. 9.16CPCh. 9.9 - Prob. 9.17CPCh. 9 - What does the indirection operator do?Ch. 9 - Look at the following code. int x = 7; int iptr =...Ch. 9 - So far you have learned three different uses for...Ch. 9 - Prob. 4RQECh. 9 - Prob. 5RQECh. 9 - Prob. 6RQECh. 9 - What is the purpose of the new operator?Ch. 9 - What happens when a program uses the new operator...Ch. 9 - Prob. 9RQECh. 9 - Prob. 10RQECh. 9 - Prob. 11RQECh. 9 - Prob. 12RQECh. 9 - Each byte in memory is assigned a unique...Ch. 9 - The _________ operator can be used to determine a...Ch. 9 - Prob. 15RQECh. 9 - The ________ operator can be used to work with the...Ch. 9 - Array names can be used as ________, and vice...Ch. 9 - Prob. 18RQECh. 9 - The ________ operator is used to dynamically...Ch. 9 - Under older compilers, if the new operator cannot...Ch. 9 - Prob. 21RQECh. 9 - When a program is finished with a chunk of...Ch. 9 - You should only use pointers with delete that were...Ch. 9 - Prob. 24RQECh. 9 - Look at the following array definition: int...Ch. 9 - Prob. 26RQECh. 9 - Assume tempNumbers is a pointer that points to a...Ch. 9 - Look at the following function definition: void...Ch. 9 - Prob. 29RQECh. 9 - Prob. 30RQECh. 9 - Prob. 31RQECh. 9 - T F The operator is used to get the address of a...Ch. 9 - T F Pointer variables are designed to hold...Ch. 9 - T F The symbol is called the indirection...Ch. 9 - T F The operator dereferences a pointer.Ch. 9 - T F When the indirection operator is used with a...Ch. 9 - T F Array names cannot be dereferenced with the...Ch. 9 - Prob. 38RQECh. 9 - T F The address operator is not needed to assign...Ch. 9 - T F You can change the address that an array name...Ch. 9 - T F Any mathematical operation, including...Ch. 9 - T F Pointers may be compared using the relational...Ch. 9 - T F When used as function parameters, reference...Ch. 9 - T F The new operator dynamically allocates memory.Ch. 9 - T F A pointer variable that has not been...Ch. 9 - Prob. 46RQECh. 9 - T F In using a pointer with the delete operator,...Ch. 9 - Prob. 48RQECh. 9 - Prob. 49RQECh. 9 - int x, ptr = nullptr; ptr = x;Ch. 9 - Prob. 51RQECh. 9 - Prob. 52RQECh. 9 - Prob. 53RQECh. 9 - float level; int fptr = level;Ch. 9 - Prob. 55RQECh. 9 - Prob. 56RQECh. 9 - Prob. 57RQECh. 9 - Prob. 58RQECh. 9 - int pint = nullptr; pint = new int[100]; //...Ch. 9 - Prob. 60RQECh. 9 - Prob. 61RQECh. 9 - Prob. 62RQECh. 9 - Array Allocator Write a function that dynamically...Ch. 9 - Test Scores #1 Write a program that dynamically...Ch. 9 - Drop Lowest Score Modify Problem 2 above so the...Ch. 9 - Test Scores #2 Modify the program of Programming...Ch. 9 - Prob. 5PCCh. 9 - Case Study Modification #1 Modify Program 9-19...Ch. 9 - Case Study Modification #2 Modify Program 9-19...Ch. 9 - Mode Function In statistics, the mode of a set of...Ch. 9 - Median Function In statistics, when a set of...Ch. 9 - Reverse Array Write a function that accepts an int...Ch. 9 - Array Expander Write a function that accepts an...Ch. 9 - Element Shifter Write a function that accepts an...Ch. 9 - Movie Statistics Write a program that can be used...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
The current source in the circuit shown generates the current pulse
Find (a) v (0); (b) the instant of time gr...
Electric Circuits. (11th Edition)
software is generally feature complete, (supposedly) bug free and ready for use by the community.
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Fill in the blanks in each of the following statements: A relation that has no partial functional dependencies ...
Modern Database Management
Write a sequence of instructions (using the operations SELECT, PROJECT, and JOIN) to retrieve the Name and JobT...
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Write a method named square that accepts an integer argument and returns the square of that argument.
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
In Exercises 41 through 46, identify the errors.
Introduction To Programming Using Visual Basic (11th 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
- Instructions: You are strictly not allowed to use anything other than pointers and dynamic memory. One function should perform one functionality only. Task 1 Write a program in C++ that reads data from a file. Create dynamic memory according to the data. Now your task is to perform the following task. Row wise Sum Column wise Sum Diagonal wise Sum Example data.txt 4 5 1.6 10.2 33.7 99 20.5 3 44 50 96.1 2 8 9 4 74 50 99 19.1 Output: Sum row wise: 165, 191, 17, 242.1 Sum col wise: 127.6, 120.1, 228.8, 118.1, 20.5 Sum diagonal wise: Not Possible Note: You are restricted to use pointers and your function should be generic. Avoid memory wastage, memory leakage, dangling pointer. Use regrow or shrink concepts if required.arrow_forwardMemory Allocation: Select all of the following statements that are true. The basic idea of contiguous allocation is that each process is contained in a single contiguous section of memory. When using a single-partition allocation scheme, the main memory is usually divided into three partitions. Memory partitioning schemes allow for multiprogramming. When applying the multiple-partition allocation scheme "Fixed Partitions", all partitions always have the same size. When applying the multiple-partition allocation scheme "Variable Partitions", the FirstFit allocation strategy performs best in practice. The Buddy system is prone to internal fragmentation.arrow_forward//Write the output of each cout statement.//Assume the size of ints to be 4 bytes.//Assume the size of pointers to ints to be 4 bytes.#include <iostream>using namespace std;int main() {int a[2][2][3]={{{1,2,3},{4,5,6}},{{7,8,9},{10,11,12}}};cout << sizeof(______) << endl; //1: ________________48___________cout << sizeof(a+0) << endl; //2: _____________________________cout << sizeof(______) << endl; //3: ____________24_________________cout << sizeof(______) << endl; //4: ______________12______________ //the address of "a" is 0x7ffee430da70cout << a << endl; //5: ______________________________________________cout << a + 0 << endl; //6: ____________________________________________cout << a + 1 << endl; //7: ____________________________________________cout << *a + 1 << endl; //8: __________________________________________cout << **a + 1 << endl; //9:…arrow_forward
- Fill-in-the-Blank You should only use the delete operator to deallocate memory that was dynamically acquired with the __________ operator.arrow_forwardd. Interface Find the number of addressess in the range if the first address is 14.7.24.0 and the last address is 14.7.27.255 Select one: a. 1024 O b. 2048 C. 512 d. 256 ch01 - Search Resul... searcharrow_forwardModify pipe4.cpp so that it accepts a message from the keyboard and sends it to pipe5. //pipe4.cpp (data producer) #include <unistd.h> #include <stdlib.h> #include <stdio.h> #include <string.h> int main() { int data_processed; int file_pipes[2]; const char some_data[] = "123"; char buffer[BUFSIZ + 1]; pid_t fork_result; memset(buffer, '\0', sizeof(buffer)); if (pipe(file_pipes) == 0) { //creates pipe fork_result = fork(); if (fork_result == (pid_t)-1) { //fork fails fprintf(stderr, "Fork failure"); exit(EXIT_FAILURE); } if (fork_result == 0) { //child sprintf(buffer, "%d", file_pipes[0]); (void)execl("pipe5", "pipe5", buffer, (char *)0); exit(EXIT_FAILURE); } else { //parent data_processed = write(file_pipes[1], some_data, strlen(some_data));…arrow_forward
- #include <stdio.h>int main() {long local;int (*mainptr)(void); /* declare a "pointer to function returning int" */mainptr = main; /* address of main */printf("%p,%p\n",&local,mainptr); /* print the two addresses */return 0;}The printf statement outputs the address of the variable “local”, which should be on the stack rightafter the return address, and then the address of the code for “main”.Start by creating a source file aslrtest.c on your VM containing the above C program. Compileit into an executable with the same name:bash$ gcc -o aslrtest aslrtest.c(As always, the “bash$” in the above represents the prompt and is not part of the command youtype.)a. Turn off ASLR with the command:echo 0 | sudo tee /proc/sys/kernel/randomize_va_spaceOnce you have ASLR disabled, run aslrtest 10 times. The following shell script will do that,(assuming your shell is bash, which it is unless you’ve changed it yourself):bash$ for i in {1..10}> do> ./aslrtest> doneWhat range of output…arrow_forwardFill-in-the-Blank The __________ operator is used to dynamically allocate memory.arrow_forwardSuppose a global variable and local variable have the same name. Is it is possible to access a global variable from a block where local variables are defined?arrow_forward
- write the code in C++arrow_forwardvoid Path() { char[] userInput =" "; system("echo $PATH"); //append the path system("export PATH=$PATH:"); scanf("%c", userInput); printf("%c", "path + %c", userInput); } PLEASE FIX THIS FUNCTION!!! (C PROGRAMMING)arrow_forwardIn c++ you have a data in a text file, the data consists of a chatacter separated by a comma then an integer also separate md by a comma then another integer Example A,11,1 B,13,2 C,14,4 D,15,7 E,40,1 F,50,1 How will you read and store the data in a vector such that the character will be stored in vector char, and the two integers will be stored in vector x and y respectively.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Systems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage LearningC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Instruction Format (With reference to address); Author: ChiragBhalodia;https://www.youtube.com/watch?v=lNdy8HREvgo;License: Standard YouTube License, CC-BY