Sub Programs (OCR GCSE Computer Science): Flashcards
📚Flashcards
Practise the cards
12 cards from this deck
ShowHide
Practise the cards
12 cards from this deck
What are sub programs?
What are sub programs?
Smaller, reusable code blocks used to structure larger programs
Two main types of sub programs
Two main types of sub programs
Functions and procedures
Do functions return a value?
Do functions return a value?
Yes, functions return a value
Do procedures return a value?
Do procedures return a value?
No, procedures do not return a value
Benefits of using sub programs
Benefits of using sub programs
Avoid repetition, easier to read/maintain, modular programming
When to use a function
When to use a function
When returning a specific result
When to use a procedure
When to use a procedure
When executing a task without needing a return value
Local variables definition
Local variables definition
Declared inside sub program, accessible only within it
Global variables definition
Global variables definition
Declared outside sub programs, accessible throughout program
Risk of global variables
Risk of global variables
Can cause unintended side effects if modified unexpectedly
Can arrays be passed to sub programs?
Can arrays be passed to sub programs?
Yes, as arguments
Can functions return arrays?
Can functions return arrays?
Yes, to process and return multiple values
