Variables and data types
Practice Flashcards
Flip to reveal answersWhat is a variable, and what does its data type decide?
Track your progress — Sign up free to save your progress and get smart review reminders based on spaced repetition.
All 5 Flashcards — Variables and data types
Sign up free to track progress and get spaced-repetition review schedules.
Question
What is a variable, and what does its data type decide?
Answer
A named place in memory holding one value. Its data type says what kind of value it is, which decides both what can be stored there and what operations work on it.
Question
Name the five data types and what each holds.
Answer
Integer: a whole number. Decimal: a number with a fractional part. Char: a single character. String: a sequence of characters. Boolean: exactly True or False.
Question
Why does + behave differently on numbers and strings?
Answer
It adds numbers and joins strings, so 12 + 1 gives 13 but "12" + "1" gives "121". Mixing the two — "12" + 1 — fails, and is one of the commonest bugs.
Question
What is the difference between a local and a global variable?
Answer
A local variable is created inside a function, cannot be seen from outside, and is destroyed when the function ends. A global variable is created outside any function and is visible throughout the program.
Question
Why are local variables preferred?
Answer
If a local value is wrong, the cause is inside that function. If a global value is wrong, any part of the program could have changed it — so the bug could be anywhere.
Read the notes
Full study notes for Variables and data types
Topic 6.1 hub
Programming fundamentals
More from Topic 6.1
All flashcards in this topic
Computer Science exam skills
Paper structures & tips
Track your progress with spaced repetition
Sign up free — Aimnova tells you exactly which cards to review and when, so you remember everything before your IB exam.
Start Free