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.2, Problem 12STE
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 array

int a[10];

// Declare variable

int *p = a;

// Declare variable

int i;

//Loop executes until the value of i exceeds 10

for (i = 0; i < 10; i++)

//Assign value i to a[i]

a[i] = i;

//Loop executes until the value of i exceeds 10

for (i = 0; i < 10; i++)

//Display value

cout << p[i] << " ";

cout << endl;

//Pause console window

system("pause");

//Return 0 value

return 0;

}

Blurred answer
Students have asked these similar questions
i.Consider the following code: Int a=5,b=a++ - 2; a)Explain what happened in above code?
Consider the following code segment:   for(int i = 0; i < 20; i++)          Z [i] = i % 2; How many values of Z are 1?
In C, Assume that the int variables i and j have been declared, and that n has been declared and initialized.Write code that causes a "triangle" of asterisks of size n to be output to the screen. Specifically, n lines should be printed out, the first consisting of a single asterisk, the second consisting of two asterisks, the third consisting of three, etc. The last line should consist of n asterisks. Thus, for example, if n has value 3, the output of your code should be******You should not output any space characters.
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