Home
Explore
Exams
Login
Get started
Home
[CP 2] M5 - Pointers and Dynamic Arrays
[CP 2] M5 - Pointers and Dynamic Arrays
0.0
(0)
Rate it
Studied by 1 person
Call Kai
Learn
Practice Test
Spaced Repetition
Match
Flashcards
Knowt Play
Card Sorting
1/66
Earn XP
Description and Tags
University/Undergrad
67 Terms
View all (67)
Star these 67
1
New cards
int *p;
What is the declaration for the pointer that points to a variable of type int?
2
New cards
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;
}
3
New cards
*
A symbol used to access the value of an address
4
New cards
&
A symbol used to determine the address of a variable
5
New cards
p now points to b
What will happen in this code?
int a \= 100, b \= 200;
int *p \= &a, *q \= &b;
p \= q;
6
New cards
&
Which of the following is a reference operator?
&
*
@
&
7
New cards
string mystring *;
Which of the following is NOT a way to declare a pointer variable?
8
New cards
All of the given
To create a dynamic array, you have to use:
"Pointer Variable
All of the given
Array
New operator"
9
New cards
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;
}
10
New cards
Memory space is allocated at runtime
Which of the following is NOT true about static arrays?
11
New cards
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;
}
12
New cards
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;
}
13
New cards
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;
}
14
New cards
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;
}
15
New cards
Pointer
It stores the memory address as its value.
16
New cards
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;
}
17
New cards
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;
}
18
New cards
int *ip;
Which of the following is illegal?
string s, *sp \= 0;
int *pi \= 0;
int *ip;
int i; double * dp \= &i;
19
New cards
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";
}
20
New cards
var1
Complete the given code:
\#include <iostream\>
using namespace std;
int main()
{
int var1 \= 17;
cout << \________ << endl;
return 0;
}
21
New cards
void pointer
It is a pointer not associated with any data types
22
New cards
new operator
Denotes a request for memory allocation on the Free Store
23
New cards
float a [10];
How a static array is declared?
24
New cards
Heap
Dynamically allocated memory is allocated on \___________________
25
New cards
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;
}
26
New cards
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;
}
27
New cards
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
28
New cards
by applying the dereference operator
What is used for accessing the contents of memory location whose address is stored in a pointer variable?
29
New cards
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;
}
30
New cards
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;
}
31
New cards
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
32
New cards
dynamic array declaration
double * p \= new double [45]; is an example of:
33
New cards
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;
}
34
New cards
ALL OF THE MENTIONED
A void pointer can point to which type of objects?
int
float
double
all of the mentioned
35
New cards
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;
}
36
New cards
45241
\#include <iostream\>
using namespace std;
int main()
{
int var \= 11;
int *ip, *ip2;
ip \= &var;
ip2 \= ip;
cout << *ip << " " << *ip2;
return 0;
}
37
New cards
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";
}
38
New cards
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;
}
39
New cards
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;
}
40
New cards
delete operator
What operator is used to free allocated memory?
41
New cards
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;
}
42
New cards
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;
}
43
New cards
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;
}
44
New cards
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;
}
45
New cards
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;
}
46
New cards
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;
}
47
New cards
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;
}
48
New cards
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;
}
49
New cards
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";
}
50
New cards
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?
51
New cards
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;
}
52
New cards
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";
}
53
New cards
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;
}
54
New cards
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;
}
55
New cards
new and delete
what functions are used in dynamic memory allocation in C++?
56
New cards
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;
}
57
New cards
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;
}
58
New cards
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;
}
59
New cards
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;
}
60
New cards
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;
}
61
New cards
143
\#include <iostream\>
using namespace std;
int main()
{
int *ptr \= new int;
int a \= 143;
ptr \= &a;
cout << *ptr << endl;
return 0;
}
62
New cards
delete
to free the dynamically allocated array pointed by pointer-variable, use:
63
New cards
new
it is used to declare memory blocks at run time (dynamically)
64
New cards
dangling pointer
a pointer that no longer points to something valid on the heap
65
New cards
delete ptr;
what is the correct syntax for deleting a pointer named ptr:
66
New cards
new operator
It requests for the memory allocation in heap
67
New cards
call the pointer
the method of passing arguments to a function copies the address of an argument into the formal parameer