AP Computer Science Principles Flashcards: Variables And Assignments

Study Variables And Assignments in AP Computer Science Principles with focused flashcards that help you recognize the idea, recall the key rule, and apply it in practice-style prompts.

AP Computer Science Principles

Variables And Assignments

0 mastered0 still learning

0% Complete

QUESTION
1/ 70

Which statement defines a variable in Python?

Tap card or press Space to flip

ANSWER

x = 10. Python uses simple assignment without type keywords.

How well did you know it?

Card 1 / 70

What this deck covers

This deck focuses on Variables And Assignments, giving you a quick way to review the definitions, rules, and examples that matter most for AP Computer Science Principles.

How to use these flashcards

Work through these flashcards in short sessions. Try to answer each prompt before flipping the card, then revisit any cards you miss until the explanation feels automatic.

All flashcards

Flashcard 1: Which statement defines a variable in Python?

Answer: x = 10. Python uses simple assignment without type keywords.

Flashcard 2: What is the output type of 'x / y' if x and y are int?

Answer: int. Integer division truncates decimal portion.

Flashcard 3: What is the result of the expression '10 - 2 * 5'?

Answer:

  1. Order of operations: 10(2×5)=010 - (2 × 5) = 0.

Flashcard 4: What does 'String name = "John";' do?

Answer: Assigns "John" to the variable name. String variable declaration and initialization.

Flashcard 5: What is a constant in programming?

Answer: A variable with a fixed value. Constants cannot be modified after initialization.

Flashcard 6: What is the result of 'x = 10 % 3;'?

Answer:

  1. Modulus returns remainder: 10÷3=310 ÷ 3 = 3 remainder 11.

Flashcard 7: What is a variable in programming?

Answer: A named storage location for data. Variables store values that can change during program execution.

Flashcard 8: What is the output type of 'x / y' if x and y are int?

Answer: int. Integer division truncates decimal portion.

Flashcard 9: What is the scope of a variable declared inside a function?

Answer: Local to that function. Function variables exist only within that function.

Flashcard 10: What is the result of 'x = 10 % 3;'?

Answer:

  1. Modulus returns remainder: 10÷3=310 ÷ 3 = 3 remainder 11.

Flashcard 11: What keyword is used to declare a variable in JavaScript?

Answer: var, let, or const. JavaScript variable declaration keywords.

Flashcard 12: What is a variable in programming?

Answer: A named storage location for data. Variables store values that can change during program execution.

Flashcard 13: Find the error: int x; x = 'hello';

Answer: Incorrect type; use int x; x = 0;. String value cannot be assigned to int type.

Flashcard 14: What type of error occurs when dividing by zero?

Answer: Arithmetic error. Division by zero is mathematically undefined.

Flashcard 15: What is variable initialization?

Answer: Assigning an initial value to a variable. Setting a variable's first value.

Flashcard 16: Which data type would you use for a true/false value?

Answer: Boolean. Boolean stores only true or false values.

Flashcard 17: Which variable name is valid: 2name, _name, name?

Answer: _name, name. Variable names cannot start with digits.

Flashcard 18: Find the error: double price = 9,99;

Answer: Use decimal point: double price = 9.99;. Use period, not comma, for decimal separator.

Flashcard 19: Identify the error: int x = '3';

Answer: Incorrect type; use int x = 3;. Single quotes denote characters, not integers.

Flashcard 20: Find the value of y after: int y = 7; y -= 2;

Answer:

  1. Subtraction assignment: 72=57 - 2 = 5.

Flashcard 21: Which statement correctly assigns a value to a variable?

Answer: x = 5;. Proper assignment syntax with equals operator.

Flashcard 22: Find the error: int x; x = 'hello';

Answer: Incorrect type; use int x; x = 0;. String value cannot be assigned to int type.

Flashcard 23: What does a 'null' value represent?

Answer: No assigned object or value. Indicates absence of any object reference.

Flashcard 24: Find the value of y after: int y = 7; y -= 2;

Answer:

  1. Subtraction assignment: 72=57 - 2 = 5.

Flashcard 25: What is the purpose of a variable declaration?

Answer: To specify a variable's type and name. Establishes variable name and data type.

Flashcard 26: What is concatenation in programming?

Answer: Joining two strings together. String concatenation combines text values.

Flashcard 27: Which data type would you use for a list of values?

Answer: Array or List. Data structures for multiple related values.

Flashcard 28: What does 'int x = 2, y = 3;' do?

Answer: Declares and initializes x and y. Multiple variable declaration in one statement.

Flashcard 29: Which data type is used for single characters?

Answer: char. Stores single Unicode characters.

Flashcard 30: What is the outcome of '3.0 / 2' in programming?

Answer: 1.5. Double division produces decimal result.

Flashcard 31: Which variable name is valid: 2name, _name, name?

Answer: _name, name. Variable names cannot start with digits.

Flashcard 32: What does 'x -= 5;' do to x?

Answer: Decreases x by 5. Compound subtraction assignment operator.

Flashcard 33: Which data type would you use for a list of values?

Answer: Array or List. Data structures for multiple related values.

Flashcard 34: Identify the error: int x = '3';

Answer: Incorrect type; use int x = 3;. Single quotes denote characters, not integers.

Flashcard 35: What symbol is used for assignment in most programming languages?

Answer: The equals sign (=). Assignment operator stores values in variables.

Flashcard 36: What symbol is used for assignment in most programming languages?

Answer: The equals sign (=). Assignment operator stores values in variables.

Flashcard 37: What is the result of '5 + 2 * 3' in programming?

Answer:

  1. Order of operations: multiplication before addition.

Flashcard 38: Identify the error: double y = 5.5.5;

Answer: Syntax error; use double y = 5.5;. Double decimal point makes number invalid.

Flashcard 39: What type of error occurs when dividing by zero?

Answer: Arithmetic error. Division by zero is mathematically undefined.

Flashcard 40: Which data type is used for single characters?

Answer: char. Stores single Unicode characters.

Flashcard 41: What does the statement 'x = x + 1' do?

Answer: Increments x by 1. Common pattern for incrementing counters.

Flashcard 42: What does a 'null' value represent?

Answer: No assigned object or value. Indicates absence of any object reference.

Flashcard 43: What does 'String name = "John";' do?

Answer: Assigns "John" to the variable name. String variable declaration and initialization.

Flashcard 44: Find the value of x after: int x = 5; x += 3;

Answer:

  1. Addition assignment operator: 5+3=85 + 3 = 8.

Flashcard 45: What happens if you exceed the range of an int variable?

Answer: Overflow occurs. Values wrap around when exceeding maximum range.

Flashcard 46: What will '++x' do if x is 5?

Answer: Increments x to 6. Pre-increment operator adds one before use.

Flashcard 47: What is the difference between 'int' and 'double'?

Answer: 'int' is for integers; 'double' is for decimals. Different data types for whole vs decimal numbers.

Flashcard 48: What does 'x -= 5;' do to x?

Answer: Decreases x by 5. Compound subtraction assignment operator.

Flashcard 49: What happens if you exceed the range of an int variable?

Answer: Overflow occurs. Values wrap around when exceeding maximum range.

Flashcard 50: What does 'int x = 2, y = 3;' do?

Answer: Declares and initializes x and y. Multiple variable declaration in one statement.

Flashcard 51: Find the value of x after: int x = 5; x += 3;

Answer:

  1. Addition assignment operator: 5+3=85 + 3 = 8.

Flashcard 52: What will '++x' do if x is 5?

Answer: Increments x to 6. Pre-increment operator adds one before use.

Flashcard 53: What is a constant in programming?

Answer: A variable with a fixed value. Constants cannot be modified after initialization.

Flashcard 54: What is the result of '5 + 2 * 3' in programming?

Answer:

  1. Order of operations: multiplication before addition.

Flashcard 55: What is the outcome of '3.0 / 2' in programming?

Answer: 1.5. Double division produces decimal result.

Flashcard 56: Find the value of z after: int z = 4; z *= 2;

Answer:

  1. Multiplication assignment: 4×2=84 × 2 = 8.

Flashcard 57: What is the result of the expression '10 - 2 * 5'?

Answer:

  1. Order of operations: 10(2×5)=010 - (2 × 5) = 0.

Flashcard 58: Find the error: double price = 9,99;

Answer: Use decimal point: double price = 9.99;. Use period, not comma, for decimal separator.

Flashcard 59: What is the difference between 'int' and 'double'?

Answer: 'int' is for integers; 'double' is for decimals. Different data types for whole vs decimal numbers.

Flashcard 60: Find the value of z after: int z = 4; z *= 2;

Answer:

  1. Multiplication assignment: 4×2=84 × 2 = 8.

Flashcard 61: What is the purpose of a variable declaration?

Answer: To specify a variable's type and name. Establishes variable name and data type.

Flashcard 62: Identify the error: double y = 5.5.5;

Answer: Syntax error; use double y = 5.5;. Double decimal point makes number invalid.

Flashcard 63: Which data type would you use for a true/false value?

Answer: Boolean. Boolean stores only true or false values.

Flashcard 64: What is the scope of a variable declared inside a function?

Answer: Local to that function. Function variables exist only within that function.

Flashcard 65: What does the statement 'x = x + 1' do?

Answer: Increments x by 1. Common pattern for incrementing counters.

Flashcard 66: What is concatenation in programming?

Answer: Joining two strings together. String concatenation combines text values.

Flashcard 67: Which statement correctly assigns a value to a variable?

Answer: x = 5;. Proper assignment syntax with equals operator.

Flashcard 68: What keyword is used to declare a variable in JavaScript?

Answer: var, let, or const. JavaScript variable declaration keywords.

Flashcard 69: What is variable initialization?

Answer: Assigning an initial value to a variable. Setting a variable's first value.

Flashcard 70: Which statement defines a variable in Python?

Answer: x = 10. Python uses simple assignment without type keywords.