wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Functions & Scope of variables in C++

Total questions: 15

Worksheet time: 7mins

Name
Class
Date
1.

The scope of a variable is

a)

the range of statements where it is visible

b)

how often it is referenced in a program

c)

how much memory it uses

d)

the number of programs it appears in

2.

What are the final values of x and y in the following code segment?


int x = 3;

int y = ++x * 5 / 2;

a)

x = 3, y = 10

b)

x = 4, y =7

c)

x = 4, y = 10

d)

x = 3, y = 7

e)

This code segment will not compile.

3.
If a functions doesn't return a value, the word ___ will appear at its return type
a)
int
b)
void
c)
static
d)
global
4.
When only a copy of an argument is passed to a function, it is said to be passed by ___
a)
value
b)
local
c)
constant
d)
reference
5.
The ____ statement causes a function to end immediately
a)
constant
b)
reference
c)
return
d)
global
6.
____ arguments are passed to parameters automatically if no argument is provided in the function call.
a)
ext
b)
constant
c)
default
d)
value
7.
Reference variables are defined like regular variables, except there is a(n) ______in front of the name
a)
@
b)
#
c)
*
d)
&
8.

Where should default parameters appear in a function prototype?

a)

Middle of the parameter list

b)

To the leftmost side of the parameter list

c)

Anywhere inside the parameter list

d)

To the rightmost side of the parameter list

9.

What will be the output of the following C++ code?

a)

10

b)

0

c)

Syntax error

d)

Segmentation fault

10.

A function __________ contains the statements that make up the function.

a)

prototype

b)

definition

c)

call

d)

expression

11.

function is executed when it is

a)

defined

b)

prototyped

c)

declared

d)

called

12.

A _________ variable is declared outside all functions.

a)

local

b)

global

c)

floating-point

d)

counter

13.

Which of the following is a complete correct function definition?

a)

int funct();

b)

int funct(int x){ x = x +1; return x; }

c)

void funct(int){ printf( “Hello”);

d)

void funct(x){ printf( “Hello”); }

14.

What will the above code display?

a)

2

2

b)

4

2

c)

2

4

d)

4

4

15.

Identify the scope operator from the following.

a)

? :

b)

::

c)

{ }

d)

[ ]