Lesson details
Key learning points
- In this lesson, we will learn about the scope of variables. When a variable is initialised within a subroutine it cannot be easily accessed and modified by other subroutines. This lesson will teach us about the different levels of scope and show us how to access variables that are initialised within subroutines.
Licence
This content is made available by Oak National Academy Limited and its partners and licensed under Oak’s terms & conditions (Collection 1), except where otherwise stated.
Loading...
3 Questions
Q1.
What will be the return value based on the function call to_the_power(3,2)?
![An image in a quiz](/_next/image?url=https%3A%2F%2Foaknationalacademy-res.cloudinary.com%2Fimage%2Fupload%2Fv1707171778%2Fvnhaucaom3zjq8cx5pad.png&w=1920&q=75)
12
3
6
Q2.
What will be the return value based on the function call find_highest(12,9)?
![An image in a quiz](/_next/image?url=https%3A%2F%2Foaknationalacademy-res.cloudinary.com%2Fimage%2Fupload%2Fv1707171785%2Fzbrdug3rfzsu4opgmtpi.png&w=1200&q=75)
3
9
No return value
Q3.
What will be the return value based on the function call multiple(30,3)?
![An image in a quiz](/_next/image?url=https%3A%2F%2Foaknationalacademy-res.cloudinary.com%2Fimage%2Fupload%2Fv1707171791%2Fwi7natpy4x2hgheieux9.png&w=1200&q=75)
No
5 Questions
Q1.
On which line is the global variable number assigned?
![An image in a quiz](/_next/image?url=https%3A%2F%2Foaknationalacademy-res.cloudinary.com%2Fimage%2Fupload%2Fv1707171634%2Fdv9yg8wnvcvqzpnun8oi.png&w=1200&q=75)
1
2
6
Q2.
On which line is the local variable number assigned?
![An image in a quiz](/_next/image?url=https%3A%2F%2Foaknationalacademy-res.cloudinary.com%2Fimage%2Fupload%2Fv1707171650%2Fehowlwunkm0rfgwmixk1.png&w=1200&q=75)
1
5
6
Q3.
What value will line 8 output when this program is executed?
![An image in a quiz](/_next/image?url=https%3A%2F%2Foaknationalacademy-res.cloudinary.com%2Fimage%2Fupload%2Fv1707171657%2Fvqdmfqj3vwfpp7lu6mr1.png&w=1080&q=75)
10
5
There will be no output
Q4.
What will happen when this program is executed?
![An image in a quiz](/_next/image?url=https%3A%2F%2Foaknationalacademy-res.cloudinary.com%2Fimage%2Fupload%2Fv1707171708%2Ftlychi5zql6ksmzkzld2.png&w=1080&q=75)
An error message because the global variable number is not defined
It will output 10
It will output 5
Q5.
On which line of code does constant declaration occur?
![An image in a quiz](/_next/image?url=https%3A%2F%2Foaknationalacademy-res.cloudinary.com%2Fimage%2Fupload%2Fv1707171712%2Fgihe020au26xotm8dnqu.png&w=750&q=75)
1
2
4