Hello I am a beginner at C++ and I was given these questions to do for my homework. I would appreciate it if you could help me answer these questions.
Consider the following code when answering questions 1-5
#include <iostream>
using namespace std;
int someVar = 10
void f(intx, int&y);
int g(int x);
int main()
{
int someVar = 3
int a = 31, b = 99;
f(a,b); //See Question 1
cout << "a = " << a << ", b = " << b << endl;
f(2*a-3,b); // See question 2
cout << " a = " << a << ", b = " << b << endl;
cout << "the value of someVar is" << someVar << endl; // See Question 3
cout << "g(3) returns the value" << g(3) << endl; // See Question 4
return 0;
}
void f(int x, int&y)
{
int someVar = 5;
x = 2;
y = 5*someVar;
}
int g(int x)
{
return someVar*x;
}
Question 1
What will be the value stored in variables "a" and "b" after the call f(a,b)?
Question 2
What will be the value stored in variables "a" and "b" after the call f(2*a-3,b)?
Question 3
What will be the value printed out for someVar?
Question 4
What will be returned by the call to function g(3)?
Question 5
What is the difference between local and global variables? Use examples from the program to explain.