Back to Topic 6.1 — Programming fundamentals
6.1.1Computer Science SL5 flashcards

Variables and data types

Practice Flashcards

Flip to reveal answers
Card 1 of 56.1.1
6.1.1
Question

What is a variable, and what does its data type decide?

Click to reveal answer

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.

Card 1definition

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.

Card 2definition

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.

Card 3concept

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.

Card 4comparison

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.

Card 5concept

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.

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