Exam 10: Pointers and Dynamic Arrays

arrow
  • Select Tags
search iconSearch Question
  • Select Tags

A pointer is an address,an address is an integer,but a pointer is not an integer.

Free
(True/False)
4.8/5
(43)
Correct Answer:
Verified

True

Give three uses for the * operator.Name and describe each use.

Free
(Essay)
4.7/5
(40)
Correct Answer:
Verified

Multiplication: x * y
Pointer definition: int *p;
Pointer dereferencing: int x;x = *p;
Pointer parameter declaration: void foo( int * p);

Your program creates a dynamically allocated array as follows: int *entry; entry = new int[10]; so that the pointer variable entry is pointing to the dynamically allocated array.Write code to fill this array with 10 numbers typed in at the keyboard.

Free
(Essay)
4.7/5
(36)
Correct Answer:
Verified

#include <iostream>
using namespace std;
int main()
{
int *entry;
entry = new int[10];
cout << "Enter 10 integers:\n";
for(int i = 0;i < 10;i++)
cin >> entry[i];
for(int i = 0;i < 10;i++)
cout << entry[i] << " ";
cout << endl;
return 0;
}

Why did C++11 introduce the nullptr constant when we already have NULL?

(Essay)
4.8/5
(29)

If a class is named MyClass,what must the destructor be named?

(Multiple Choice)
4.9/5
(37)

Suppose we have the following definitions and assignments: double *p,v; p = &v;// p gets the address of v What is the effect of this assignment? *p = 99.99

(Short Answer)
4.8/5
(30)

Dynamic variables or dynamically allocated variables in C++ are created and destroyed according to the program's needs.

(True/False)
4.7/5
(38)

It is an error to call the delete operator on a pointer a second time.Consider what happens if there is memory allocated on the free store for a class,a destructor,and initializing constructors have been defined,but no copy constructor was defined.Now suppose a function is called that has call-by-value parameters.Why does the program either die in the middle or give a segmentation fault?

(Essay)
4.9/5
(43)

Give the sequence of steps for creating and using a dynamic array.

(Essay)
4.8/5
(40)

Pointer variables are just memory addresses and can be assigned to one another without regard to type.

(True/False)
4.9/5
(26)

There should eventually be a call to the operator delete on a pointer that points to the memory allocated by each call to new.

(True/False)
4.9/5
(42)

Given the definitions, int *p1,*p2; p1 = new int; p2 = new int; You are to compare and contrast the two assignments. a)p1 = p2; b)*p1 = *p2

(Essay)
4.8/5
(29)

A pointer is a variable that holds the address of some other location in memory.

(True/False)
4.9/5
(46)

Write a type definition for pointer variables that will point to dynamically allocated arrays whose base type is char.The name of the type will be CharArray.

(Short Answer)
4.8/5
(53)

In deep copy,pointers are followed and data and the pointer structure are duplicated.

(True/False)
4.8/5
(37)

An array name is a constant pointer to array base type.

(True/False)
4.9/5
(32)

Give the output from this code fragment: int *p1,*p2; p1 = new int; p2 = new int; *p1 = 10; *p2 = 20; cout << *p1 << " " << *p2 << endl; *p1 = *p2; cout << *p1 << " " << *p2 << endl; *p1 = 30; cout << *p1 << " " << *p2 << endl;

(Short Answer)
4.8/5
(40)

The default copy constructor and default operator = provide deep copy.

(True/False)
4.8/5
(46)

You can get a pointer value to initialize a pointer variable from an object of an appropriate type with the "address-of" operator,&.

(True/False)
4.9/5
(42)

When declaring several pointer variables,there must be one pointer declarator * for each pointer variable.

(True/False)
4.8/5
(46)
Showing 1 - 20 of 29
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)