SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,julia Lobur
Chapter:
Pointers And Dynamic Arrays
Exercise:
Self-test Exercises
Question:15 | ISBN:9780321531346 | Edition: 7

Question

What is the output of the following code fragment? The code is assumed

to be embedded in a correct and complete program.


int array_size = 10;

int *a;

a = new int[array_size];

int i;

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

a[i] = i;

while (*a < 9)

{

a++;

cout << *a << " ";

}

cout << endl;

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

OUTPUT:

Complete Program Code:

#include <iostream>
using namespace std;

int main()
{
	int array_size = 10;
	int *a;
	a = new int[array_size];
	int i;
	for (i = 0; i < array_size; i++)
		a[i] = i;
	while (*a < 9)
	{
		a++;
		cout << *a << " ";
	}
	cout << endl;
	system("PAUSE");
}

 

0 0

Discussions

Post the discussion to improve the above solution.