Questions

I'm trying to answer a couple questions for self checking. I believe I know the answers, but would like someone else's opinion. Thanks in advance.

Q1.

A variable defined inside a function is referred to as?

My answer:

a global variable

Other Choices:

*a local variable
*a function variable
*a block variable


Q2.

When invoking a function with a reference object parameter, ________ is passed.

My answer:

the reference of the object

Other Choices:

*the object is copied, then the reference of the copied object
*the contents of the object
*a copy of the object
Q1. No.

A global variable is a variable that is not defined inside a function and anything can access it (which is why you shouldn't them 98% of the time).

1
2
3
4
5
6
7
8
9
10
11
12
13
int x = 5; //Global Variable

void Func()
{
	int y = 6; // Local Variable
	// Can access x or y, but not z directly
}

int main()
{
	int z = 7; // Local Variable
	// Can access x or z, but not y directly
}


Q2 answer seems correct but I would get a second opinion, I haven't looked into the technical definition for passing by reference, so there might be some catch.
@James2250,

Thank you, so you're saying for Q1 the answer is local variable?
Correct.
Thank you.
Topic archived. No new replies allowed.