Font size
WorksheetsFunctions & Scope of variables in C++
Total questions: 15
Worksheet time: 7mins
The scope of a variable is
the range of statements where it is visible
how often it is referenced in a program
how much memory it uses
the number of programs it appears in
What are the final values of x and y in the following code segment?
int x = 3;
int y = ++x * 5 / 2;
x = 3, y = 10
x = 4, y =7
x = 4, y = 10
x = 3, y = 7
This code segment will not compile.
Where should default parameters appear in a function prototype?
Middle of the parameter list
To the leftmost side of the parameter list
Anywhere inside the parameter list
To the rightmost side of the parameter list
What will be the output of the following C++ code?
10
0
Syntax error
Segmentation fault
A function __________ contains the statements that make up the function.
prototype
definition
call
expression
function is executed when it is
defined
prototyped
declared
called
A _________ variable is declared outside all functions.
local
global
floating-point
counter
Which of the following is a complete correct function definition?
int funct();
int funct(int x){ x = x +1; return x; }
void funct(int){ printf( “Hello”);
void funct(x){ printf( “Hello”); }
What will the above code display?
2
2
4
2
2
4
4
4
Identify the scope operator from the following.
? :
::
{ }
[ ]
