Chapter 9 Quiz Practice

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

If p1 is an integer pointer that is pointing to memory location 1001, and an integer takes 4 bytes, then (p1+1) evaluates to

1005.

What is the output of the following code? int *p1, *p2; p1 = new int; p2 = new int; *p1=11; *p2=0; p2=p1; cout << *p1 <<" " << *p2 << endl;

11 11

What is the output of the following code fragment? int v1=2, v2=-1, *p1, *p2; p1 = & v1; p2= & v2; p2=p1; cout << *p2 << endl;

2

What is the output of the following code fragment? float *p1; p1 = new float(3); cout << *p1;

3.0

If two pointer variables point to the same memory location, what happens when one of the pointers is freed?

A and C

Assuming that the pointer variable p1 is of the correct type and size is an integer with some value > 1, which of the following declarations are legal?

A, B, and C

If p1 and p2 are both pointers that point to integers in memory, the condition p1==p2 will be true if the values that are in those memory locations are the same.

False

The size of dynamic arrays must be declared at compile time.

False

int *p1; declares a static variable.

False

Dynamically created variables have no name.

True

You can assign an array to a pointer variable.

True

1 out of 1 points Given that p1 is a pointer variable of the string class, which of the following are legal statements?

cout << *p1;

Which of the following statements correctly prints out the value that is in the memory address that the pointer p1 is pointing to?

cout << *p1;

Which of the following correctly declare 3 integer pointers?

int *p1, *p2, *p3;

If a program requires a dynamically allocate two-dimensional array, you would allocate the memory by using

p1 = new int*[numRows]; for(int i=0; i < numRows; i++) p1[i] = new int[numColumns];

Which of the following correctly declares a dynamic array of strings?

p1 = new string[13];

Which of the following assigns to p1 the pointer to the address of value?

p1=&value;

Which of the following correctly declares a user-defined data type that defines a pointer to a float?

typedef float* floatPtr;

Given that a typedef for IntPtr defines a pointer to an integer, what would be the correct declaration for a function that expects a reference to an integer pointer?

void f1 (IntPtr& ptr);

Given that p1 is an integer pointer variable, and ā is an integer array, which of the following statements are NOT legal code?

ā1 = p1;


संबंधित स्टडी सेट्स

Module 19/20 - Introduction to Ecology

View Set

Principles of Management - Final Exam Cate Loes

View Set

Texas Principles of Real Estate 1 - Chapter 12

View Set

Accounting Smart Books, Assignments, etc.

View Set

Ch 3. License Application and Administration

View Set

Express Employment Professionals Business Office Technology Certification Review

View Set

Chapter 4: Common Reproductive Issues

View Set

Ch. 22 Assessment of Integumentary System

View Set

MRKT Ch. 6 Consumer Behavior and Marketing Strategies

View Set