click below
click below
Normal Size Small Size show me how
COMPROG 5
| Question | Answer |
|---|---|
| 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; } | Pizza |
| 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; } | 40 |
| What will happen in this code? int a = 100, b = 200; int *p = &a, *q = &b; p = q; | p now points to b |
| A symbol used to determine the address of a variable | & |
| Which of the following is a reference operator? | & |
| 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; } | fg |
| Choose the right option: string* x, y; | x is a pointer to a string, y is a string |
| It is a pointer not associated with any data types. | Void pointer |
| Which of the following is NOT a way to declare a pointer variable? | string mystring *; |
| 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 |
| What is the declaration for the pointer that points to a variable of type int? | int *p; |
| 0x7fffe867d790 is an example of: | Memory Address |
| A symbol used to access the value of an address | * |
| To create a dynamic array, you have to use: | new operator, pointer variable and array/All of the given – |
| 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; } | 143 |
| 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; } | 8 |
| 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;} | Memory Address |
| How a static array is declared? | float a [10]; |
| 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 |
| It stores the memory address as its value. | Pointer |
| Dynamically allocated memory is allocated on ___________________. | Heap |
| What operator is used to free allocated memory? | Delete operator [] |
| What is used for accessing the contents of memory location whose address is stored in a pointer variable? | By applying the dereference operator |
| Which of the following is NOT true about static arrays? | Memory space is allocated at runtime |
| When does the void pointer can be dereferenced? | When it cast to another type of object – |
| Which of the following is NOT true about dynamic arrays? | Memory space is allocated during compile time |
| Complete the given code: #include <iostream> using namespace std; int main() { int var1 = 17; cout << ________ << endl; return 0;} | var1 |
| Denotes a request for memory allocation on the Free Store. | new operator |
| double * p = new double [45]; is an example of: | Dynamic Array Declaration |
| 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 |
| which of the following is illegal? 1. int i; double *dp = &i; 2. int *ip; 3. int *pi = 0; 4. string s, *sp = 0; | int i; double *dp = &i; |
| #include <iostream> using namespace std; int main() { int *foo; foo[0] = 1; foo[1] = 2; foo[2] = 3; foo[3] = 4; foo[4] = 5; delete[] foo; cout; return 0; } | none |
| #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; (TRUNCATED) | 100 200 300 400 500 |
| #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; } | 90 |
| #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; } | error |
| #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; } | 1 2 3 4 5 |
| #include <iostream> using namespace std; int main() { string food = "Pizza"; string* ptr = &food; cout << food << " "; cout << *ptr << "\n"; } | Pizza Pizza |
| what will happen in this code? int a = 100, b = 200; int *p = &a, *q = &b; p = q; | p now points to b |