(1 point) USER NAME: ___________________________
-------------------------------------------
pass 1: | | | | | | | |
-------------------------------------------
0 1 2 3 4 5 6
-------------------------------------------
pass 2: | | | | | | | |
-------------------------------------------
0 1 2 3 4 5 6
    1.
    2.
b. What are the two things that free() does?
    1.
    2.
const int N = 8; int i, A[N] = {0, 11, 22, 33, 44, 55, 66, 77}; for (i = 0; i < N-1; i++) // notice: N-1 A[i] = A[i+1]; _________________________________________ | | | | | | | | | original A: | 0 | 11 | 22 | 33 | 44 | 55 | 66 | 77 | |---------------------------------------| 0 1 2 3 4 5 6 7 _________________________________________ | | | | | | | | | new A: | | | | | | | | | |---------------------------------------| 0 1 2 3 4 5 6 7
vector
}
KEY
1a. 48 b. 33
2. i = 0;
power = 1;
while(i <= 6) {
cout << i << setw(4) << power << endl;
i++;
power *= 2;
}
3. 2
4. 0 1 2 3 4 5
-------------------------
0 | | | | | | |
-------------------------
1 | | | | | | |
-------------------------
2 | | | | | | |
-------------------------
3 | * | * | * | | | |
-------------------------
4 | * | * | * | | | |
-------------------------
5 | * | * | * | | | |
-------------------------
5. 286
6. pass 1: 13 35 77 41 22 62 54
pass 2: 13 22 77 41 35 62 54
7a. 1. malloc() allocates the requested amount of space from the heap, and
2. malloc() returns the address of the allocated space.
b. 1. free() returns to the heap the space pointed to by its argument, and
2. the pointer is then undefined.
8. 11 22 33 44 55 66 77 77
9. int my_cmp (char *one, char *two)
{
int i, result;
i = 0;
result = 999;
while(result == 999) {
if(one[i] < two[i]) result = -1;
else if(one[i] > two[i]) result = 1;
else if(one[i] == '\0') result = 0;
i++; cout << i << endl;
}
return result;
}
10a. 2 b. -180
11. if(x != y && x == 100) cout << "yes\n";
else cout << "no\n";
12. It reverses the digits of x.
13a. It skips over leading blanks in the input.
b. a non-blank character
14. 43 71 47
15. Number of elements in list: 10
16. In trace: 4 57
In main: 43 57
17. vector read_it(vector v)
{
int i;
for(i = 0; i < v.size() && !cin.eof(); i++)
cin >> v[i];
return v;
}
18. int factorial(int n)
{
int fact = 1;
while(n != 0) {
fact *= n;
n--;
}
return fact;
}