Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. What is the last number output by the following code? Enter \"nothing\" if it

ID: 3566674 • Letter: 1

Question

1. What is the last number output by the following code? Enter "nothing" if it produces no output.

#include <iostream>
using namespace std;
const int NUM = 10;
void food_on_table ()
{
static int food = NUM;
food--;
cout << food << endl;
}
int main ()
{
for (int i=0;i<5;i++)
{
food_on_table();
}
return 0;
}

2. What is the output of the following code? Your output must be exact! Enter "nothing" if it produces no output.

#include <iostream>
using namespace std;
int foo();
int main()
{
int x=0;
x=foo();
x=a;
return 0;
}
int foo()
{
int a,b,x;
a=100;
b=100;
x=a*b;
return x;
}

3. What is the output of the following code? Your output must be exact! Enter "nothing" if it produces no output.

#include <iostream>
using namespace std;
int foo();
int main()
{
int x=0;
cout << "Go";
x=foo();
return x;
}
int foo()
{
cout << "Hokies!";
return 1;
}

4. What is the output for the last value of B in the following code? Enter "nothing" if it produces no output.

#include <iostream>
using namespace std;
void TestA (int &Y, int Z)
{
   Y++;
   Z++;
    return;
}

void TestB (int Y, int& Z)
{
   Y*=2;
   Z*=2;
    return;
}

void TestC (int &Y, int& Z)
{
   Y++;
   Z++;
    return;
}

int main (void)
{    
   int A=5, B=7;

   TestA(A, B);                  
    cout << "LINE 1: " << A << ", " << B << endl;  
    TestB(A, B);                  
    cout << "LINE 2: " << A << ", " << B << endl;  
    TestC(A, B);                  
    cout << "LINE 3: " << A << ", " << B << endl;  
   return 0;
}

Explanation / Answer

a) For the first code,

correct answers are 9,8,7,6,5

Hence last printed output is 5

b) For the second code,

Nothing will be printed in this case, since a is not declared in the above scope

c) For the third code,

Output - GoHokies!

d) For the fourth code,

Output: LINE 3: 7, 15