Program Outputs (College Board AP® Computer Science Principles): Revision Note
Output generation & dependencies
What is program output?
Output is the data or information that a program produces as a result of its processing
Output can take many forms depending on the device or destination it is sent to
For example:
Text on a screen (text)
Image on a screen (visual)
Sound from a speaker (audio)
Phone vibration (tactile)
A program may produce different types of output at different points during its execution
How is output generated?
Output is generated when a program processes input and internal data according to its instructions
The output a program produces at any given moment depends on:
The input it has received
The current program state (the values stored in all variables at that point in execution)
The logic and sequence of statements in the program
Program state changes as the program runs, so the same line of code can produce different output at different times depending on what has happened before it
Output dependencies
A dependency exists when one part of a program's output relies on another part of the program completing first
Programs often produce intermediate results that feed into later calculations or displays
Understanding dependencies is important for predicting what a program will output and in what order
Errors caused by dependencies are among the most common bugs in programs
If statements are reordered or a variable is updated at the wrong point, the output may be incorrect even though each individual statement appears to be right
Examiner Tips and Tricks
When the AP exam asks what a program will display, trace through the code and track how the program state changes with each statement. The output depends on the state at the moment the output statement executes, not the state at the start of the program.
If a question asks about dependencies, look for variables that are set in one part of the code and used in another. The second part depends on the first.
For the AP Create Performance Task, your program must produce output based on input and processing. On exam day, be prepared to trace through your code and explain what your program displays or returns at key points during execution.
Worked Example
Consider the following code segment.
x ← 5
y ← x + 3
x ← 10
DISPLAY(y)
//The AP exam uses ← for assignment and DISPLAY() for output
What value is displayed when this code segment is executed?
(A) 5
(B) 8
(C) 10
(D) 13
[1]
Answer:
(B) 8 [1 mark]
When
y ← x + 3executes,xis 5, soyis assigned 8. Reassigningxto 10 afterwards does not affect the value already stored iny.
Unlock more, it's free!
Was this revision note helpful?