## CSCI 3300 Fall 2013 Exercises for Quiz 2

1. What is the value of g(4), given the definition of g below? (Hint. Work out g(1), then g(2), then g(3), then g(4), in that order. Keep your work organized.)

```  int g(int n)
{
if(n == 1) return 2;
else return g(n-1) + 3;
}
```

2. Write a C++ definition of function sum(a,b) that returns a + (a+1) + ... + b. For example, sum(2,5) = 2 + 3 + 4 + 5 = 14. More precisely, sum(a,b) returns the sum of all integers that greater than or equal to a and less than or equal to b. For this question do not use any kind of loop. Use recursion instead.

3. Redo the previous exercise, but this time use a loop, not recursion.

4. What does jump( ) return, where jump is writtten below, using function jumpHelper?

``` void jumpHelper(int x)
{
x = x + 1;
}

void jump()
{
int z = 40;
jumpHelper(z);
return z;
}
```

5. What does hop( ) return, where hop is writtten below, using function hopHelper?

``` void hopHelper(int& x)
{
x = x + 1;
}

void hop()
{
int z = 40;
hopHelper(z);
return z;
}
```

6. What does romp( ) return, where romp is written below, using function rompHelper?

``` void rompHelper(int a, int& b)
{
b = a + 2;
a = b + 1;
}
int romp()
{
int x = 4;
int y = 25;
rompHelper(x,y);
return x + y;
}
```

7. Which of the following will create an array of 30 integers called Orange in the run-time stack?

1. int Orange;
2. int* Orange;
3. int Orange;
4. int[] Orange;