Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

Problem 1

Mark the following statements as true or false. a. In C++, pointer is a reserved word. b. In C++, pointer variables are declared using the word pointer. c. The statement delete p; deallocates the variable pointer p. d. The statement delete p; deallocates the dynamic variable that is pointed to by p. e. Given the declaration: int list[10]; int *p; the statement: p = list; is valid in C++. f. Given the declaration: int *p; the statement: p = new int[50]; dynamically allocates an array of 50 components of type int, and p contains the base address of the array. g. The address of operator returns the address and value of its operand. h. If p is a pointer variable, then the statement p = p * 2; is valid in C++.

Problem 2

Given the declaration: int x; int *p; int *q; mark the following statements as valid or invalid. If a statement is invalid, explain why. a. p = q; b. *p = 56; c. p = x; d. *p = *q; e. q = &x f. *p = q;

Problem 3

Explain how the operator * is used to work with pointers.

Problem 4

Consider the following statement: int* p, q; This statement could lead to what type of misinterpretation?

Problem 5

What is the output of the following C++ code? int x; int y; int *p = &x int *q = &y *p = 35; *q = 98; *p = *q; cout << x << " " << y << endl; cout << *p << " " << *q << endl;

Problem 6

What is the output of the following C++ code? int x; int y; int *p = &x int *q = &y x = 35; y = 46; p = q; *p = 78; cout << x << " " << y << endl; cout << *p << " " << *q << endl;

Problem 7

Given the declaration: int num = 6; int *p = # which of the following statements increment(s) the value of num? a. p++; b. (*p)++; c. num++; d. (*num)++;

Problem 8

What is the output of the following code? int *p; int *q; p = new int; q = p; *p = 46; *q = 39; cout << *p << " " << *q << endl;

Problem 9

What is the output of the following code? int *p; int *q; p = new int; *p = 43; q = p; *q = 52; p = new int; *p = 78; q = new int; *q = *p; cout << *p << " " << *q << endl;

Problem 10

What is the output of the following C++ code? int *p; int *q; p = new int; q = new int; *p = 27; *q = 35; cout << *p << " " << *q << endl; q = p; *q = 73; cout << *p << " " << *q << endl; p = new int; *p = 36; *q = 42; cout << *p << " " << *q << endl;

Access millions of textbook solutions in one place

  • Access over 3 million high quality textbook solutions
  • Access our popular flashcard, quiz, mock-exam and notes features
  • Access our smart AI features to upgrade your learning
Get Vaia Premium now
Access millions of textbook solutions in one place

Recommended explanations on Computer Science Textbooks