Starting Out With C++: Early Objects, Student Value Edition (9th Edition)
9th Edition
ISBN: 9780134379319
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 10.10, Problem 10.14CP
Assume ip is a pointer to an int. Write a statement that will dynamically allocate an array of 500 integers and store its address in ip, then write a statement that will free the memory allocated in the statement you just wrote.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
1)Answer the question with the correct option
A) Which of the following assigns to the pointer p to the address of value? options are given
p = value;
*p = &value;
p = &value;
p = &value;
1)Answer the question with the correct option
A) Which of the following assigns to the pointer p to the address of value? options are given
p = value;
*p = &value;
p = &value;
p = &value;
B) What is the output of the following code fragment? Options are given below the code:
int v1=2, v2=-1, *p1, *p2; p1 = &v1; p2 = &v2; p2 = p1; cout << *p2 << endl;
2
-2
1
-1
C) Which of the following statements correctly prints out the value that is in the memory address that the pointer p is pointing to?
cout << int* p;
cout << p;
cout << *p;
cout << &p;
// Program 4.6.1
#include <iostream>using namespace std;int main (){int X = 5, Y = 15; int * p1, * p2;p1 = &X; // p1 = address of Xp2 = &Y; // p2 = address of Y*p1 = 10; // value pointed by p1 = 10*p2 = *p1; // value pointed by p2 = value pointed by p1p1 = p2; // p1 = p2 (value of pointer is copied)*p1 = 40; // value pointed by p1 = 20cout << "X is " << X << endl;cout << "Y is " << Y << endl;return 0;}
TASK
1. Explain in details what the program does?
2. What is the output
Chapter 10 Solutions
Starting Out With C++: Early Objects, Student Value Edition (9th Edition)
Ch. 10.5 - Prob. 10.1CPCh. 10.5 - Write a statement defining a variable dPtr. The...Ch. 10.5 - List three uses of the symbol in C++.Ch. 10.5 - What is the output of the following program?...Ch. 10.5 - Rewrite the following loop so it uses pointer...Ch. 10.5 - Prob. 10.6CPCh. 10.5 - Assume pint is a pointer variable. For each of the...Ch. 10.5 - For each of the following variable definitions,...Ch. 10.10 - Assuming array is an array of ints, which of the...Ch. 10.10 - Give an example of the proper way to call the...
Ch. 10.10 - Complete the following program skeleton. When...Ch. 10.10 - Look at the following array definition: const int...Ch. 10.10 - Assume ip is a pointer to an int. Write a...Ch. 10.10 - Assume ip is a pointer to an int. Write a...Ch. 10.10 - Prob. 10.15CPCh. 10.10 - Prob. 10.16CPCh. 10.10 - Prob. 10.17CPCh. 10.12 - Prob. 10.18CPCh. 10.12 - Assume the following structure declaration exists...Ch. 10.12 - Prob. 10.20CPCh. 10 - Each byte in memory is assigned a unique _____Ch. 10 - The _____ operator can be used to determine a...Ch. 10 - Prob. 3RQECh. 10 - The _____ operator can be used to work with the...Ch. 10 - Prob. 5RQECh. 10 - Creating variables while a program is running is...Ch. 10 - Prob. 7RQECh. 10 - If the new operator cannot allocate the amount of...Ch. 10 - Prob. 9RQECh. 10 - When a program is finished with a chunk of...Ch. 10 - You should only use the delete operator to...Ch. 10 - What does the indirection operator do?Ch. 10 - Look at the following code. int X = 7; int ptr =...Ch. 10 - Name two different uses for the C++ operator.Ch. 10 - Prob. 15RQECh. 10 - Prob. 16RQECh. 10 - Prob. 17RQECh. 10 - What is the purpose of the new operator?Ch. 10 - What happens when a program uses the new operator...Ch. 10 - Prob. 20RQECh. 10 - Prob. 21RQECh. 10 - Prob. 22RQECh. 10 - Prob. 23RQECh. 10 - Prob. 24RQECh. 10 - Prob. 25RQECh. 10 - Prob. 26RQECh. 10 - What happens when a unique_ptr that is managing an...Ch. 10 - What does the get ( ) method of the unique_ptr...Ch. 10 - Prob. 29RQECh. 10 - Prob. 30RQECh. 10 - Prob. 31RQECh. 10 - Prob. 32RQECh. 10 - Consider the function void change(int p) { P = 20;...Ch. 10 - Prob. 34RQECh. 10 - Write a function whose prototype is void...Ch. 10 - Write a function void switchEnds(int array, int...Ch. 10 - Given the variable initializations int a[5] = {0,...Ch. 10 - Each of the following declarations and program...Ch. 10 - Prob. 39RQECh. 10 - Test Scores #1 Write a program that dynamically...Ch. 10 - Test Scores #2 Modify the program of Programming...Ch. 10 - Indirect Sorting Through Pointers #1 Consider a...Ch. 10 - Indirect Sorting Through Pointers #2 Write a...Ch. 10 - Pie a la Mode In statistics the mode of a set of...Ch. 10 - Median Function In statistics the median of a set...Ch. 10 - Movie Statistics Write a program that can be used...Ch. 10 - Days in Current Month Write a program that can...Ch. 10 - Age Write a program that asks for the users name...Ch. 10 - Prob. 10PC
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
What does the Java code Scanner keyboard = new Scanner(System.in); keyboard.useDelimiter("y"); System.out.print...
Java: An Introduction to Problem Solving and Programming (8th Edition)
Create a class ShuffleCipher that implements the interface MessageEncoder, as described in Exercise 15. The con...
Java: An Introduction to Problem Solving and Programming (7th Edition)
Why might doctors and nutritionists be interested in a device like DietSensor?
Using MIS (10th Edition)
Square Display Write a program that asks the user for a positive integer no greater than 15. The program should...
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Extreme programming expresses user requirements as stories, with each story written on a card. Discuss the adva...
Software Engineering (10th 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
- What is the address of (int) m[i][j] in terms of the base address and COLS? What are potential problems with <code>strcpy()</code> and <code>strcat</code> Why does <code>scanf()</code> take a pointer?arrow_forward// Program 4.4.1#include <iostream>using namespace std;int main (){ int var = 20; // actual variable declaration. int *ip; // pointer variable ip = &var; // store address of var in pointer variable cout << "Value of var variable: "; // print the variable value cout << var << endl<<endl; cout << "Address stored in ip variable: "; // print the address stored in ip pointer variable cout << ip << endl<<endl; cout << "Value of *ip variable: "; // access the value at the address available in pointer cout << *ip << endl; return 0;} TASK 1. Explain in details what the program does? 2. What is the output.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
- Write a short C program that declares and initializes (to any value you like) adouble, an int, and a char. Next declare and initialize a pointer to each of thethree variables. Your program should then print the address of, and value storedin, and the memory size (in bytes) of each of the six variables.Use the “%p” formatting specifier to print addresses in hexadecimal. You shouldsee addresses that look something like this: "0xbfe55918". The initial characters"0x" tell you that hexadecimal notation is being used; the remainder of the digitsgive the address itself. Use proper formatting specifiers for char, int and double.Use the sizeof operator to determine the memory size allocated for each variable.Sample output from your program:The address of char ___ is 0x_______The address of int ___ is 0x_______The address of double ___ is 0x_______The address of char* ___ is 0x_______The address of int* ___ is 0x_______The address of double* ___ is 0x_______The value of char ___ is _______The…arrow_forwardWrite a C program that uses the following: a main() to read two integer values from the user, val1 and val2, and prints the returned value from swap().a swap() that uses call by reference (takes the addresses into pointers) to swap values, and prints their values after the swap "num1 = # and num2 = #". This function returns the largest of the two values. If these are equal, it returns their sum.arrow_forwardGiven the declaration below, if array aData[][] was associated to the memory location 1010 (in decimal), what is the value/address (in decimal) equivalent to aData[5] ? double aData[6][4]; Note that sizeof(double) results to 8, meaning 8 bytes.arrow_forward
- Write a short C program that declares and initializes (to any value you like) adouble, an int, and a char. Next declare and initialize a pointer to each ofthe three variables. Your program should then print the address of, and valuestored in, and the memory size (in bytes) of each of the six variables.Use the “0x%x” formatting specifier to print addresses in hexadecimal. Youshould see addresses that look something like this: "0xbfe55918". The initialcharacters "0x" tell you that hexadecimal notation is being used; the remainderof the digits give the address itself.Use the sizeof operator to determine the memory size allocated for eachvariable.*/arrow_forwardWhat is the correct way to assign the pointer p to the address of x?. Single choice. p = %x; p = &x; &p = *x; *p = &x;arrow_forwardWrite a block of code that uses a dynamic allocated array named Array to (1) Load ten integers from the user into the memory, (2) Find the number of negative integers in the array, and (3) Print a message with the number of negatives. Whenever no numbers are negative print an additional message "No negatives!" (Assume all libraries are included)arrow_forward
- Declare a character field, assign values to it (e.g. Next, declare a pointer to this field and write the actual address it points to on the screen (eg printf (“% p”, pointer);). Then change the address value (add a unit). Enter a value for this address and return the string to the screen. What has happened? Finally, change the address value to a very high value and try writing something again. What happens? The program should fall. Explain why. Explan all codes.thanksarrow_forwardWith the code below,dynamic memory allocation is not utilized at the main function. Rewrite the main function to incorporate dynamic allocation. #include<iostream>using namespace std;class Student{private:string studid, name; float marks[2], average;public:void setInput(){cout<<"Please enter student id :";getline(cin,studid);cout<<"Please enter name :";getline(cin,name);cout<<"\n\n";}void setMarks(){for(int i=0;i<2;i++){cout<<"Please enter mark for quiz "<<(i+1)<<" :";cin>>marks[i];calculate_average();} }void calculate_average(){float total;for(int i=0;i<2;i++){total += marks[i];}average = total / 2;}friend void display_info(Student);};void display_info(Student s){cout<<"\n\n\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>"<<endl;cout<<" Result Score "<<endl;cout<<"----------------------------"<<endl;cout<<"ID Name Average…arrow_forwardPLEASE MODIFY THE BELOW CODE BY USING INTERRUPTS. #include <iostream>#include <cstdlib>#include <time.h>#include <chrono>#include <pthread.h> using namespace std::chrono;using namespace std;#define NUM_THREADS 40 struct AddTask{int *v1,*v2,*v3;int start;int end;}; void randomVector(int vector[], int size){for (int i = 0; i < size; i++){ vector[i] = rand() % 100;}} void *AddVector(void* arg){ AddTask *task = (struct AddTask *) arg; for(int i = task->start; i< task->end ; i++){task->v3[i] = task->v2[i] + task->v1[i];}} int main(void){ pthread_t threads[NUM_THREADS]; unsigned long size = 100000000; srand(time(0)); int *v1, *v2, *v3; auto start = high_resolution_clock::now(); v1 = (int *) malloc(size * sizeof(int *));v2 = (int *) malloc(size * sizeof(int *));v3 = (int *) malloc(size * sizeof(int *)); randomVector(v1, size); randomVector(v2, size); for (size_t i = 0; i < NUM_THREADS; i++) {struct AddTask *task = (struct…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher: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