Program Outputs (College Board AP® Computer Science Principles): Study Guide

Robert Hampton

Written by: Robert Hampton

Reviewed by: James Woodhouse

Updated on

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 + 3 executes, x is 5, so y is assigned 8. Reassigning x to 10 afterwards does not affect the value already stored in y.

Unlock more, it's free!

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Robert Hampton

Author: Robert Hampton

Expertise: Computer Science Content Creator

Rob has over 16 years' experience teaching Computer Science and ICT at KS3 & GCSE levels. Rob has demonstrated strong leadership as Head of Department since 2012 and previously supported teacher development as a Specialist Leader of Education, empowering departments to excel in Computer Science. Beyond his tech expertise, Robert embraces the virtual world as an avid gamer, conquering digital battlefields when he's not coding.

James Woodhouse

Reviewer: James Woodhouse

Expertise: Computer Science & English Subject Lead

James graduated from the University of Sunderland with a degree in ICT and Computing education. He has over 14 years of experience both teaching and leading in Computer Science, specialising in teaching GCSE and A-level. James has held various leadership roles, including Head of Computer Science and coordinator positions for Key Stage 3 and Key Stage 4. James has a keen interest in networking security and technologies aimed at preventing security breaches.