Save
Busy. Please wait.
Log in with Clever
or

show password
Forgot Password?

Don't have an account?  Sign up 
Sign up using Clever
or

Username is available taken
show password


Make sure to remember your password. If you forget it there is no way for StudyStack to send you a reset link. You would need to create a new account.
Your email address is only used to allow you to reset your password. See our Privacy Policy and Terms of Service.


Already a StudyStack user? Log In

Reset Password
Enter the associated with your account, and we'll email you a link to reset your password.
focusNode
Didn't know it?
click below
 
Knew it?
click below
Don't Know
Remaining cards (0)
Know
0:00
Embed Code - If you would like this activity on your web page, copy the script below and paste it into your web page.

  Normal Size     Small Size show me how

CP2-Module 5

Pointers and Dynamic Arrays

QuestionAnswer
Which of the following is NOT a way to declare a pointer variable? string* mystring; string mystring *; string * mystring; string *mystring; string mystring *;
A symbol used to access the value of an address & $ * # *
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; } 20 1 0 40 20
Which of the following is illegal? int i; double * dp = &i; int *ip; int *pi = 0; string s, *sp = 0; int *pi = 0; //unsure, it should be the "int i; double * dp = &i;" but no. Also not "string s, *sp = 0;"
Which of the following is a reference operator? * @ & & &
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; } 11 11 Error 22 11 11 11
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"; } Pizza Pizza 0 Pizza Error Pizza Pizza // not error, still runs without "return 0;"
What is the declaration for the pointer that points to a variable of type int? int *p; int(p); INT *p; int p; int *p;
A symbol used to determine the address of a variable # $ & * &
What will happen in this code? int a = 100, b = 200; int *p = &a, *q = &b; p = q; p now points to b a is assigned to b q now points to a b is assigned to a p now points to b
Dynamically allocated memory is allocated on ___________________ Heap Array Variable Stack Heap
#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; } Output is? 1 2 3 4 5
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; } Error
Denotes a request for memory allocation on the Free Store Group of answer choices delete operator dereferencing operator new operator address operator new operator
What is used for accessing the contents of memory location whose address is stored in a pointer variable? By applying the address operator & By applying some special function By applying the dereference operator By applying an array By applying the dereference operator
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; } NULL 8 Error 0 8
Which of the following is NOT true about dynamic arrays? Group of answer choices Memory space is allocated at runtime Memory space is allocated during compile time Dynamic size Located in Heap memory space Memory space is allocated during compile time
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; } 10 10 10
It stores the memory address as its value Group of answer choices Data type Pointer Identifier Variable Pointer
How a static array is declared? Group of answer choices float * p = new float [5]; float a [10]; int n; string s; float a [10];
A pointer can NOT be stored in a variable. True or False? False, a pointer can be stored in a variable.
The * operator is also called the dereferencing operator. True or False? True
The & operator is also called the address-of operator. True or False? True
The new operator creates a new dynamic variable of a specified type and returns a pointer that points to this new variable. True or False? True
The delete operator eliminates a dynamic variable and returns the memory that the dynamic variable occupied to the ROM. True or False? False, it returns the memory to the freestore, also known as heap.
When you apply delete to a pointer variable, the dynamic variable it is pointing to is created. True or False? False, it is destroyed.
Variables created with the new operator are called dynamic variables because they are created and destroyed while the program is running. True or False? True
You can assign a name to a type definition and then use the type name to declare variables. This is done with the keyword typedefinition. True or False? False, it is only written as "typedef"
You can declare a dynamic array using the variable type double. True or False? False, you should only use int.
Created by: Easy Kwatro
Popular Computers sets

 

 



Voices

Use these flashcards to help memorize information. Look at the large card and try to recall what is on the other side. Then click the card to flip it. If you knew the answer, click the green Know box. Otherwise, click the red Don't know box.

When you've placed seven or more cards in the Don't know box, click "retry" to try those cards again.

If you've accidentally put the card in the wrong box, just click on the card to take it out of the box.

You can also use your keyboard to move the cards as follows:

If you are logged in to your account, this website will remember which cards you know and don't know so that they are in the same box the next time you log in.

When you need a break, try one of the other activities listed below the flashcards like Matching, Snowman, or Hungry Bug. Although it may feel like you're playing a game, your brain is still making more connections with the information to help you out.

To see how well you know the information, try the Quiz or Test activity.

Pass complete!
"Know" box contains:
Time elapsed:
Retries:
restart all cards