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.)
question
Write a c++ program that follows the program requirements below
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
- How may the address of a variable be added to a pointer variable? Why is the code below problematic?arrow_forward16. NULL can be assigned to a void pointer. True O Falsearrow_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_forward
- Create a program in C language that calculates the month's day from a given year and year's day. Use pointers for the month and month's day variables. Don't forget to add proper errors handling in your program. Example or errors - Invalid Input- Invalid year- Invalid year day Example of input # ./month_day <year> <yearday> # Example for Feb 2nd, 2019:\$ ./month-day 2019 33Feb 02, 2019 I have this class - month-day.c - #include <stdio.h> /* month_day function's prototype*/void month_day(int year, int yearday, int *pmonth, int *pday); int main() {return 0;} Note: I don't need the calendar, please read the instructions well!!arrow_forwardAssuming that ptr is a pointer to an int, what happens when you add 4 to ptr ?arrow_forwardExplain the difference between a pointer variable and other variables such as int, float, char.arrow_forward
- write 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_forwardIn C Languagearrow_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_forward
- Create 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_forwardAssume ptr is a pointer, the following expressions has the same values *&ptr and ptr? Select one: a. True b. Falsearrow_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