STARTING OUT WITH C++ MPL
9th Edition
ISBN: 9780136673989
Author: GADDIS
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 10.5, Problem 10.6CP
Program Plan Intro
Pointer:
Pointer, the name itself references the purpose of the pointer. Pointers point to a location in memory.
- Pointer is a special type of variable to store the address of the memory location, which can be accessed later.
- If an asterisk “*” operator is present before the variable, then that variable is referred as pointer variable.
- It is also called as dereferencing or indirection operator.
- Pointer is just a type of variable that stores the addresses of other variables.
- Using pointers, we can access the address of a variable; the data stored in that variable can be retrieved.
Syntax of pointer variable declaration:
<variable-type> *<variable-name>;
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Using C++ programming language:
Assume intptr is a pointer to an int. Write a statement that will dynamically allocate an array of 100 integers and store its address in intptr. Also, write a statement that will free the memory allocated in the statement you just wrote.
Using C++ Programming language:
Given the following definitions:
int num1=1, num2=2;
int *ptr1=NULL, *ptr2=NULL;
Write the following statements:
Assign ptr1 to the address of num1.
Assign ptr2 to the address of num2.
Using pointer notation, write a statement that compares the values that the pointers "point" to to see which is larger. (There is more than one way to do this. You choose.)
How may the address of a variable be added to a pointer variable? Why is the code below
problematic?
Chapter 10 Solutions
STARTING OUT WITH C++ MPL
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
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
- IN C PROGRAMMING LANGUAGE: Please write a pointer version of strncmp() named pstr_ncmp(char *s, char *t, int n) which compares the first n characters.arrow_forwardwrite a single statement that performs the specified task. Assume that long variables value1 and value2 have been declared and value1 has been initialized to 200000 ."Assign the address of variable value1 to pointer variable longPtr .arrow_forwardIN C PROGRAMMING LANGUAGE: Please write a pointer version of strncpy() named pstr_ncpy(char *dest, char *src, int n) which copies n characters from src and copies them into dest.arrow_forward
- Explain the difference between a pointer variable and other variables such as int, float, char.arrow_forwardAddress of Array//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 8 bytes.int main() {int a[3][3]={{1,2,3},{4,5,6},{7,8,9}};cout << sizeof(a) << endl: //1: ___________________________cout << sizeof(a+0) << endl: //2: _____________________________cout << sizeof(*(a+0)) << endl: //3: _____________________________cout << sizeof(**a) << endl; //4: ____________________________cout << sizeof(&a) << endl; //5: _____________________________Assume the address of "a" is 0x7ffee2fef9e0cout << a + 1 << endl; //6: ________________________________________cout << *a + 1 << endl; //7: ________________________________________cout << **a + 1 << endl; //8: _______________________________________cout << &a << endl; //9: __________________________________________cout << &a + 1 << endl; //10:…arrow_forwardwrite C++ statements that perform the specified task. Assume that unsigned integers are stored in four bytes and that the starting address of the built-in array is at location 1002500 in memory. " Write two separate statements that assign the starting address of built-in array values to pointer variable vPtr ."arrow_forward
- In C Language Pleasearrow_forwardWrite a program in C++ that inputs a number in an integer variable. It stores the address of variable in a pointer and then displays the value and the address of the variable. The screen dialog should appear as follows: Enter an integer 25 The value of n: 25 The address of n: 0x234f6arrow_forwardCreate a function that can accept a pointers and array with values of 1000, 2, 3, 17, 50. Your program will display the array values and its averagearrow_forward
- Create a program and flowchart for the following: Write a program that uses random-number generation to create sentences. The program should use four arrays of pointers to char called article, noun, verb and preposition. The program should create a sentence by selecting a word at random from each array in the following order: article, noun, verb, preposition, article and noun. As each word is picked, it should be concatenated to the previous words in an array large enough to hold the entire sentence. The words should be separated by spaces. When the final sentence is output, it should start with a capital letter and end with a period. The program should generate 20 such sentences. The arrays should be filled as follows: The article array should contain the articles "the", "a", "one", "some" and "any"; the noun array should contain the nouns "boy", "girl", "dog", "town" and "car"; the verb array should contain the verbs "drove", "jumped", "ran", "walked" and "skipped"; the preposition…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_forwardCode: //POinters #include<iostream> using namespace std; int main() { int var = 9; int *ip; double *dp; float *fp; char *ch; ip=&var; //&= address of (saves address of variable var in ip) cout<<"Variable Value "<<var<<endl; cout<<"Address saved in pointer "<<ip<<endl; cout<<"Pointer pointing to value "<<*ip<<endl; *ip=50; cout<<"\nVariable Value "<<var<<endl; cout<<"Address saved in pointer "<<ip<<endl; cout<<"Pointer pointing to value "<<*ip<<endl; } //Dynamic Memory Allocation #include<iostream> using namespace std; int main() { int size,i; int *ptr; cout<<"Enter size of an array"<<endl; cin>>size; ptr = new int[size]; cout<<"Enter Array Elements to store\n"; for(i=0;i<size;i++) { cin>>ptr[i]; } cout<<"Values of Array are\n"; for(i=0;i<size;i++) { cout<<ptr[i]<<endl; } for(i=0;i<size;i++) {…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