Problem Solving with C++ (9th Edition)
Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
Publisher: PEARSON
Question
Book Icon
Chapter 9.1, Problem 5STE
Program Plan Intro

Pointer in C++:

A pointer is a variable whose value will be another variable’s address. Generally, a pointer variable is declared as follows:

type *var-name;

Here, type is the pointer’s base type and var-name is the pointer variable name. The asterisk is used to designate a variable as a pointer.

Given Program:

//Include libraries

#include <iostream>

//Use namespace

using namespace std;

//Define main method

int main()

{

// Declare pointer variables

int *p1, *p2;

//Assign value

p1 = new int;

//Assign value

p2 = new int;

//Assign value

*p1 = 10;

//Assign value

*p2 = 20;

//Display value

cout << *p1 << " " << *p2 << endl;

//Assign value

*p1 = *p2;

//Display value

cout << *p1 << " " << *p2 << endl;

//Assign value

*p1 = 30;

//Display value

cout << *p1 << " " << *p2 << endl;

//Pause console window

system("pause");

//Return 0 value

return 0;

}

Blurred answer
Students have asked these similar questions
int j; for (int i = 0; i < 5; i++)   {j = 2*j*i;} What is j?
int f(int &k){k++;return k * 2;}int main(){int i = 1, j = -1;int a, b, c;a = f(i) + i/2;b = j + f(j) + f(j);c = 2 * f(j);return 0;} What are the values of a, b and c id the operands in the expressions are evaluated from left to right and then what are the values when its evaluated right to left?
int a = -2, b = 5, c = 1, d = 11, e = -5; int x = e + d - 2; a = b - c + x; b = e * x + 5; c = d / 3  - x; d = b + c - 7; e = a + c - x;   a =  b =  c =  d =  e =
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education