[CP 2] M5 - Pointers and Dynamic Arrays

studied byStudied by 1 person
0.0(0)
Get a hint
Hint

int *p;

1 / 66

flashcard set

Earn XP

Description and Tags

67 Terms

1

int *p;

What is the declaration for the pointer that points to a variable of type int?

New cards
2

20

What is the output of the following?

\#include <iostream\>

using namespace std;

int main()

{

int var \= 20;

int *ip;

ip \= &var;

cout << *ip << endl;

return 0;

}
New cards
3

A symbol used to access the value of an address

New cards
4

&

A symbol used to determine the address of a variable

New cards
5

p now points to b

What will happen in this code?

int a = 100, b = 200;

int *p = &a, *q = &b;

p = q;

New cards
6

&

Which of the following is a reference operator? &

@

&

New cards
7

string mystring *;

Which of the following is NOT a way to declare a pointer variable?

New cards
8

All of the given

To create a dynamic array, you have to use:

"Pointer Variable All of the given Array New operator"

New cards
9

It depends on user input

How many number 5 will display based on the given program?

\#include <iostream\>

using namespace std;

int main() {

int n;

cin \>> n;

int * p \= new int[n];

for (int i \= 0; i<n;i++)

{

p[n] \= 5;

cout << p[n] << " ";

}

delete []p;

return 0;

}
New cards
10

Memory space is allocated at runtime

Which of the following is NOT true about static arrays?

New cards
11

Error

What is the output of the program?

\#include <iostream\>

using namespace std;

int main() {

int * foo;

foo \= new int [5];

foo[0] \= 1;

foo[1] \= 2;

foo[2] \= 3;

foo[3] \= 4;

foo[4] \= 5

delete[] foo;

cout ;

return 0;

}
New cards
12

143

What is the output of the given program?

\#include <iostream\>

using namespace std;

int main()

{

int *ptr \= new int;

int a \= 143;

ptr \= &a;

cout << *ptr << endl;

return 0;

}
New cards
13

A memory address

What is the output of the program?

\#include <iostream\>

using namespace std;

int main()

{

int *ptr \= new int;

int a \= 143;

ptr \= &a;

cout << ptr << endl;

return 0;

}
New cards
14

1 2 3 4 5

What is the output of the following?

\#include <iostream\>

using namespace std;

int main() {

int * foo;

foo \= new int [5];

foo[0] \= 1;

foo[1] \= 2;

foo[2] \= 3;

foo[3] \= 4;

foo[4] \= 5;

for (int i \= 0; i < 5; i++)

{

cout << foo[i] << " ";

}

delete[] foo;

return 0;

}
New cards
15

Pointer

It stores the memory address as its value.

New cards
16

90

What is the output of the following?

\#include <iostream\>

using namespace std;

int main() {

int *p1 \= new int();

int *p2 \= new int();

int *p3 \= new int();

*p1 \= 45;

p2 \= p1;

*p3 \= *p1+*p2;

cout << *p3 << endl;

return 0;

}
New cards
17

100 200 300 400 500

What is the output of the following program?

\#include <iostream\>

using namespace std;

int main()

{

int *dArray;

dArray \= new int [3];

dArray[0] \= 100;

dArray[1] \= 200;

dArray[2] \= 300;

for (int i \= 0; i < 3; i++)

cout << dArray[i] << " ";

delete []dArray;

dArray \= new int [2];

dArray[0] \= 400;

dArray[1] \= 500;

for (int i \= 0; i < 2; i++)

cout << dArray[i] << " ";

delete []dArray;

return 0;

}
New cards
18

int *ip;

Which of the following is illegal?

string s, *sp = 0;

int *pi = 0;

int *ip;

int i; double * dp = &i;

New cards
19

Pizza Pizza

What is the output of the following program?

\#include <iostream\>

using namespace std;

int main()

{

string food \= "Pizza";

string * ptr \= &food;

cout << food << " ";

cout << *ptr << "\n";

}
New cards
20

var1

Complete the given code:

\#include <iostream\>

using namespace std;

int main()

{

int var1 \= 17;

cout << \________ << endl;

return 0;

}
New cards
21

void pointer

It is a pointer not associated with any data types

New cards
22

new operator

Denotes a request for memory allocation on the Free Store

New cards
23

float a [10];

How a static array is declared?

New cards
24

Heap

Dynamically allocated memory is allocated on ___________________

New cards
25

error

What is the output of the given program?

\#include <iostream\>

using namespace std;

int main()

{

int a[2];

a[0] \= 12;

a[1] \= 12;

int a[3];

a[0] \= 12;

a[1] \= 12;

a[3] \= 12;

return 0;

}
New cards
26

8

What is the output of the following?

\#include <iostream\>

using namespace std;

int main() {

int * foo \= new int [5];

foo[0] \= 8;

cout << foo [0];

delete[] foo;

return 0;

}
New cards
27

memory space is allocated during compile time

Which of the following is NOT true about dynamic arrays? Group of answer choices

Memory space is allocated during compile time

Memory space is allocated at runtime

Located in Heap memory space

Dynamic size

New cards
28

by applying the dereference operator

What is used for accessing the contents of memory location whose address is stored in a pointer variable?

New cards
29

143

What is the output of the given program?

\#include <iostream\>

using namespace std;

int main()

{

int *ptr \= new int;

int a \= 143;

ptr \= &a;

cout << *ptr << endl;

return 0;

}
New cards
30

90

What is the output of the following?

\#include <iostream\>

using namespace std;

int main() {

int *p1 \= new int();

int *p2 \= new int();

int *p3 \= new int();

*p1 \= 45;

p2 \= p1;

*p3 \= *p1+*p2;

cout << *p3 << endl;

return 0;

}
New cards
31

x is a pointer to a string, y is a string

Choose the right option:

string* x, y;

Group of answer choices

x is y

x is a pointer to a string, y is a string

this statement produces an error

both x and y are pointer to string types

New cards
32

dynamic array declaration

double * p = new double [45]; is an example of:

New cards
33

100 200 300 400 500

What is the output of the following program?

\#include <iostream\>

using namespace std;

int main()

{

int *dArray;

dArray \= new int [3];

dArray[0] \= 100;

dArray[1] \= 200;

dArray[2] \= 300;

for (int i \= 0; i < 3; i++)

cout << dArray[i] << " ";

delete []dArray;

dArray \= new int [2];

dArray[0] \= 400;

dArray[1] \= 500;

for (int i \= 0; i < 2; i++)

cout << dArray[i] << " ";

delete []dArray;

return 0;

}
New cards
34

ALL OF THE MENTIONED

A void pointer can point to which type of objects?

int

float

double

all of the mentioned

New cards
35

fg daw

What is the output of this program?

#include < iostream >

using namespace std;

int main()

{

char *ptr;

char Str[] = "abcdefg";

ptr = Str;

ptr += 5;

cout << ptr;

return 0;

}

New cards
36

45241

\#include <iostream\>

using namespace std;

int main()

{

int var \= 11;

int *ip, *ip2;

ip \= &var;

ip2 \= ip;

cout << *ip << " " << *ip2;

return 0;

}
New cards
37

Pizza Pizza

What is the output of the following program?

\#include <iostream\>

using namespace std;

int main()

{

string food \= "Pizza";

string * ptr \= &food;

cout << food << " ";

cout << *ptr << "\n";

}
New cards
38

40

What is the output of the following?

\#include <iostream\>

using namespace std;

int main()

{

int var \= 40;

int *ip;

ip \= &var;

cout << *ip << endl;

//cout << "40";

return 0;

}
New cards
39

20

What is the output of the following?

\#include <iostream\>

using namespace std;

int main()

{

int var \= 20;

int *ip;

ip \= &var;

cout << *ip << endl;

return 0;

}
New cards
40

delete operator

What operator is used to free allocated memory?

New cards
41

40461

What is the output of the following program?

\#include <iostream\>

using namespace std;

int main() {

int n;

n \= 3;

int * p \= new int[n];

for (int i \= 0; i<n;i++)

{

p[n] \= 10;

cout << p[n] << " ";

}

delete []p;

return 0;

}
New cards
42

it depends on user input

How many number 5 will display based on the given program?

\#include <iostream\>

using namespace std;

int main() {

int n;

cin \>> n;

int * p \= new int[n];

for (int i \= 0; i<n;i++)

{

p[n] \= 5;

cout << p[n] << " ";

}

delete []p;

return 0;

}
New cards
43

100 200 300 400 500

What is the output of the following program?

\#include <iostream\>

using namespace std;

int main()

{

int *dArray;

dArray \= new int [3];

dArray[0] \= 100;

dArray[1] \= 200;

dArray[2] \= 300;

for (int i \= 0; i < 3; i++)

cout << dArray[i] << " ";

delete []dArray;

dArray \= new int [2];

dArray[0] \= 400;

dArray[1] \= 500;

for (int i \= 0; i < 2; i++)

cout << dArray[i] << " ";

delete []dArray;

return 0;

}
New cards
44

error

What is the output of the program?

\#include <iostream\>

using namespace std;

int main() {

int * foo;

foo \= new int [5];

foo[0] \= 1;

foo[1] \= 2;

foo[2] \= 3;

foo[3] \= 4;

foo[4] \= 5

delete[] foo;

cout ;

return 0;

}
New cards
45

8

What is the output of the following?

\#include <iostream\>

using namespace std;

int main() {

int * foo \= new int [5];

foo[0] \= 8;

cout << foo [0];

delete[] foo;

return 0;

}
New cards
46

1 2 3 4 5

What is the output of the following?

\#include <iostream\>

using namespace std;

int main() {

int * foo;

foo \= new int [5];

foo[0] \= 1;

foo[1] \= 2;

foo[2] \= 3;

foo[3] \= 4;

foo[4] \= 5;

for (int i \= 0; i < 5; i++)

{

cout << foo[i] << " ";

}

delete[] foo;

return 0;

}
New cards
47

error

What is the output of the given program?

\#include <iostream\>

using namespace std;

int main()

{

int a[2];

a[0] \= 12;

a[1] \= 12;

int a[3];

a[0] \= 12;

a[1] \= 12;

a[3] \= 12;

return 0;

}
New cards
48

a memory address

What is the output of the program?

\#include <iostream\>

using namespace std;

int main()

{

int *ptr \= new int;

int a \= 143;

ptr \= &a;

cout << ptr << endl;

return 0;

}
New cards
49

Pizza Pizza

What is the output of the following program?

\#include <iostream\>

using namespace std;

int main()

{

string food \= "Pizza";

string * ptr \= &food;

cout << food << " ";

cout << *ptr << "\n";

}
New cards
50

None of the mentioned

"By its definition a void pointer does not point to data of a specific type. Therefore you cannot de-reference a void pointer

when it cast to another type of object yung tamang sagot"

When does the void pointer can be dereferenced?

New cards
51

Pizza

What is the output of the following code?

\#include <iostream\>

using namespace std;

int main()

{

string food \= "Pizza";

string* ptr \= &food;

cout << food << "\n";

return 0;

}
New cards
52

Pizza Pizza

What is the output of the following program?

\#include <iostream\>

using namespace std;

int main()

{

string food \= "Pizza";

string * ptr \= &food;

cout << food << " ";

cout << *ptr << "\n";

}
New cards
53

Pizza

What is the output of the following code?

\#include <iostream\>

using namespace std;

int main()

{

string food \= "Pizza";

string* ptr \= &food;

cout << food << "\n";

return 0;

}
New cards
54

20

What is the output of the following?

\#include <iostream\>

using namespace std;

int main()

{

int var \= 20;

int *ip;

ip \= &var;

cout << *ip << endl;

return 0;

}
New cards
55

new and delete

what functions are used in dynamic memory allocation in C++?

New cards
56

45241

What is the output of the following?

\#include <iostream\>

using namespace std;

int main()

{

int var \= 11;

int *ip, *ip2;

ip \= &var;

ip2 \= ip;

cout << *ip << " " << *ip2;

return 0;

}
New cards
57

40461

What is the output of the following program?

\#include <iostream\>

using namespace std;

int main() {

int n;

n \= 3;

int * p \= new int[n];

for (int i \= 0; i<n;i++)

{

p[n] \= 10;

cout << p[n] << " ";

}

delete []p;

return 0;

}
New cards
58

90

What is the output of the following?

\#include <iostream\>

using namespace std;

int main() {

int *p1 \= new int();

int *p2 \= new int();

int *p3 \= new int();

*p1 \= 45;

p2 \= p1;

*p3 \= *p1+*p2;

cout << *p3 << endl;

return 0;

}
New cards
59

100 200 300 400 500

\#include <iostream\>

using namespace std;

int main()

{

int *dArray;

dArray \= new int [3];

dArray[0] \= 100;

dArray[1] \= 200;

dArray[2] \= 300;

for (int i \= 0; i < 3; i++)

cout << dArray[i] << " ";

delete []dArray;

dArray \= new int [2];

dArray[0] \= 400;

dArray[1] \= 500;

for (int i \= 0; i < 2; i++)

cout << dArray[i] << " ";

delete []dArray;

return 0;

}
New cards
60

It depends on user input

How many number 5 will display based on the given program?

\#include <iostream\>

using namespace std;

int main() {

int n;

cin \>> n;

int * p \= new int[n];

for (int i \= 0; i<n;i++)

{

p[n] \= 5;

cout << p[n] << " ";

}

delete []p;

return 0;

}
New cards
61

143

\#include <iostream\>

using namespace std;

int main()

{

int *ptr \= new int;

int a \= 143;

ptr \= &a;

cout << *ptr << endl;

return 0;

}
New cards
62

delete

to free the dynamically allocated array pointed by pointer-variable, use:

New cards
63

new

it is used to declare memory blocks at run time (dynamically)

New cards
64

dangling pointer

a pointer that no longer points to something valid on the heap

New cards
65

delete ptr;

what is the correct syntax for deleting a pointer named ptr:

New cards
66

new operator

It requests for the memory allocation in heap

New cards
67

call the pointer

the method of passing arguments to a function copies the address of an argument into the formal parameer

New cards

Explore top notes

note Note
studied byStudied by 83 people
... ago
5.0(1)
note Note
studied byStudied by 16332 people
... ago
4.9(156)
note Note
studied byStudied by 131 people
... ago
5.0(1)
note Note
studied byStudied by 13 people
... ago
5.0(1)
note Note
studied byStudied by 208 people
... ago
5.0(1)
note Note
studied byStudied by 35 people
... ago
5.0(1)
note Note
studied byStudied by 81 people
... ago
5.0(1)
note Note
studied byStudied by 41100 people
... ago
4.9(218)

Explore top flashcards

flashcards Flashcard (85)
studied byStudied by 3 people
... ago
5.0(1)
flashcards Flashcard (21)
studied byStudied by 13 people
... ago
5.0(1)
flashcards Flashcard (98)
studied byStudied by 26 people
... ago
5.0(1)
flashcards Flashcard (100)
studied byStudied by 10 people
... ago
5.0(1)
flashcards Flashcard (61)
studied byStudied by 6 people
... ago
5.0(1)
flashcards Flashcard (63)
studied byStudied by 7 people
... ago
5.0(1)
flashcards Flashcard (67)
studied byStudied by 25 people
... ago
5.0(1)
flashcards Flashcard (31)
studied byStudied by 5 people
... ago
5.0(1)
robot