Problem Solving With C++ (Looseleaf) - With Access
Problem Solving With C++ (Looseleaf) - With Access
9th Edition
ISBN: 9780133835267
Author: 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
What is the output of this code, multiple choice? See attached picture. A. There is no output from this code   B. You are passing,   C. You are passing,You are passing,
Write the output of the following code:mister_pet = Pet("Master", "Dog")mister_dog = Dog("Mister", True)mister_cat = Cat("Tom",False)mister_cat_2 = Cat("Bully", True)print(mister_dog.getName())print(mister_pet.getName())print(mister_cat.getName())print(mister_cat_2.hatesDogs())print(mister_cat.hatesDogs())
What output will be produced by this code segment:  for (int i = 5; i > 1; i--)  {    for (int j = i - 1; j > 1; j--)      System.out.print (3 * j - 1);    System.out.println();  }
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning