Description
Use the tables, values and code excerpts below to answer the questions given at the end of this challenge
Table 1
variable | int a | int b | int c | int * pa | int * pb | int * pc | int * pd |
address | 1024 | 2048 | 3172 | 4096 | 4100 | 4104 | 4108 |
value | 50 | 75 | 100 |
Table 2
For the C-string below, assume that text begins at address 8196
char text[16] = “Spring Break”
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
S | p | r | i | n | g | B | r | e | a | k | \0 | s | a | u |
Copy Table 1 and Table 2 onto a piece of paper (use a pencil!). Then, mentally “execute” the sequence of code below. With each line that you execute, update your tables with the new values.
Given the above variables, manually determine the new values in Table 1 and Table 2, based on each line of code running sequentially as given below:
pa = &a; // manually update the new value of pa in Table 1 pb = &b; // manually update the new value of pb in Table 1 pc = pb; // and so on... pd = new int; *pa = *pa * 2; b = b + 75; *pd = c + *pc; text[13] = 'e'; *(text + 6) = '\0';
What is displayed by the following code? (Indicate accordingly if the values are invalid, unknown, or would produce a compilation error)
01) cout << &b; 02) cout << a; 03) cout << &pa; 04) cout << b + c; 05) cout << *pb + *pc; 06) cout << a + *pb; 07) cout << *pd; 08) cout << pd; 09) cout << pc; 10) cout << &a; 11) cout << *a; 12) cout << c *a; 13) cout << text[0]; 14) cout << *(text + 1) << text[3] << *(text + 13); 15) cout << &(text[5]); 16) cout << text;
CATALOG ID: CPP-EX0001