Starting Out with C++: Early Objects
Starting Out with C++: Early Objects
8th Edition
ISBN: 9780133360929
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: Addison-Wesley
Expert Solution & Answer
Book Icon
Chapter 10, Problem 30RQE

A)

Explanation of Solution

Purpose of the given statement:

The purpose of the statement is to declare a pointer variable as a null pointer.

Syntax error:

An error which is occurred on the source code of a program is referred as “syntax error”; because the computer programs are strictly follows the syntax rules, if the code fails to prove its language syntax format then the compiler will throws an error...

B)

Explanation of Solution

Analysis of the given statement:

In the given statement, a variable “x” of integer data type is declared, a pointer variable “ptr” is declared. Next statement is defined such a pointer variable holds the address of the variable “x”.

Given statements:

//variable declaration

int x, *ptr;//line 1

//assign the address to a pointer variable

C)

Explanation of Solution

Analysis of the given statement:

In the given statement, a variable “x” of integer data type is declared, a pointer variable “ptr” is defined. Next statement is defined with a pointer variable to hold the address of the variable “x”.

Given statements:

//variable declaration

int x , * ptr;

//assign the address of “x” to the “ptr”

*ptr = &x;

Corrected code:

//v...

D)

Explanation of Solution

Analysis of the given statement:

  • In the given statement, a variable “x” of integer data type is declared, a pointer variable “ptr” is declared .
  • Next statement is defined such a pointer variable holds the address of the variable “x”.
  • The next statement is defined to assign the value of “x” to be “100” in the “ptr”. The next statement is used to display the value of “x”.

Given statements:

//variable declaration

int x, *ptr;

//assign the address of the x to the pointer

ptr = &x;

//assign the value of x to be 100

ptr = 100; // Store 100 in x

//display the value of x

cout << x ...

E)

Explanation of Solution

Analysis of the given statement:

  • In the given statements an array is defined and declared with value.
  • Next is a display statement.
  • Displays the third element of the array using pointers.

Given statements:

//array declaration

int numbers[] = { 10, 20 , 30, 40 , 50 };

//display statement

cout << "The third element in the array is ";

//displays third value present in the array.

cout << *numbers + 3 << endl;

Corrected code:

//array ...

F)

Explanation of Solution

Analysis of the given statement:

  • In the given statements an array is defined to hold “20” values and a pointer variable “iptr” is declared.
  • Next statement is assigning the value of the array to a pointer.
  • Next statement is to perform a multiplication operation using a pointer variable which is invalid.

Given statements:

/*Variable declaration to hold 20 values and a pointer variable that holds zero address */

int values[20] , *iptr;

//assign the value to a pointer variable

iptr = values;

//perform multiplication operation

iptr *...

G)

Explanation of Solution

Analysis of the given statement:

  • A variable of double data type is declared.
  • The next statement assigns the address of the variable to a variable of type integer.

Given statements:

//variable declaration

double level;

//address of pointer variable is assigned to a variable

int dptr = &level

Error in the above statement:

  • The address of the variable “level” of &...

H)

Explanation of Solution

Analysis of the given statement:

  • A pointer variable of integer data type is declared and defined to hold the address of an uninitialized variable.
  • In the next statement a variable of integer data type is declared.

Given statements:

//variable declaration and definition

int *iptr = &ivalue;

//variab...

I)

Explanation of Solution

Analysis of the given statement:

  • A function named “doubleVal” is passed with an integer type variable “val”.
  • The parameter value that is passed is multiplied by two.

Given statements:

//method definition

void doubleVal (int val) //line 1

{

//multiply the val by 2

*val *= 2; //line 2

}

Error p...

J)

Explanation of Solution

Analysis of the given statement:

  • A new pointer is declared and assigned.
  • The second statement tries to dynamically allocate memory for the pointer that is defined.

Given statements:

//pointer variable declaration

int *pint; //line 1

//dynamically allocate memory...

K)

Explanation of Solution

Analysis of the given statement:

  • A new pointer is declared.
  • The memory for pointer variable is allocated dynamically.
  • Value “100” is assigned to the pointer variable.

Given statements:

//pointer variable declared with zero address

int *pint; //line 1

//dynamically allocate memory space

pint = new int; //line 2

//assign the value 100 to the pointer variable

pint = 100; //line 3

Error...

L)

Explanation of Solution

Analysis of the given statement:

  • A pointer variable of integer data type is declared and defined to hold the address of an uninitialized variable.
  • An array of 100 elements gets allocated dynamically.
  • De-allocation of the dynamically allocated memory.

Given statements:

//pointer variable that is assigned with zero address

int *pint; // line 1

//dynamically allocate the array

pint = new int[100]; // line 2

/*Code that processes the array.

.

.

.

.

.

.

.

.

.

*/

// Free the memory

delete pint; // line 3

Error present in the above statement:

The declared variable is an array pointer, In “Line 3”, “delete” operation is defined for the array pointer is invalid...

M)

Explanation of Solution

Analysis of the given statement:

  • A method named “getNum()” is provided with a definition.
  • Variable named “wholeNum” is declared of integer data type.
  • The user is prompted to enter a number and get it as an input.
  • The address of the variable “wholeNum” is returned.

Given statements:

//method definition

int *getNum()//line 1

{

//variable declaration

int whol...

Blurred answer

Chapter 10 Solutions

Starting Out with C++: Early Objects

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 - Consider the function void change(int p) { P = 20;...Ch. 10 - Prob. 26RQECh. 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 - Prob. 30RQECh. 10 - Prob. 31RQECh. 10 - Test Scores #1 Write a program that dynamically...Ch. 10 - Test Scores #2 Modify the program of Programming...Ch. 10 - Prob. 3PCCh. 10 - Prob. 4PCCh. 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...
Knowledge Booster
Background pattern image
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