struct Pair
{
int first;
int second;
};
correct the following snippets of code, or if there is nothing wrong, say there is nothing wrong:
(a) Pair * pair; pair.first = 0; (b) Pair[] pairs; pairs[0] -> first = 0; (c) Pair pairs[5]; *pairs.first = 0; (d) Pair * pairs[5]; (*pairs).first = 0; (e) Pair * p = Pair[5]; p -> first = 0; (f) Pair & p = new Pair[5]; p -> first = 0;4a. What is another name for the variable &a[0] ?
void print(int a[], unsigned int length)
{
for (unsigned int i = 0; i < length; ++i)
{
std::cout << *(a + i) << "\r";
}
}
6. This one is a little tricky. What does the following function compute? Explain your answer.
int f(int a[], unsigned int length)
{
int x = *a, *b = a;
while (b != a + length)
{
if (*b > x)
x = *(b++);
else
b++;
}
return x;
}
© 2003 UC Riverside Department of Computer Science & Engineering. All rights reserved.