Basic Types and Variables Flashcards
What are the main technological areas that have seen significant advancements over the past 20 years?
Mobile devices, the cloud, artificial intelligence, and self-driving cars.
What was the analytical engine?
The analytical engine was an early computing device that used mechanical gears and was computed by manually moving hand cranks.
What is binary code?
Binary code consists of two digits, 0 and 1, which represent different electrical states in a computer.
Example: 0 is off, and 1 is on.
Why do computers use binary code?
Computers only understand binary code because it represents two states (on and off) which are easy to represent with electrical signals.
What is an example of decimal to binary conversion?
Decimal 1 is binary 1, Decimal 2 is binary 10, Decimal 3 is binary 11.
What is the CPU?
The CPU, or Central Processing Unit, is the brain of the computer that processes instructions and performs calculations.
What happens when a program is written in any language?
It needs to be compiled or interpreted into machine-readable code (binary) so that the computer can execute it.
Why don’t humans program in binary?
Binary code is hard to read and error-prone for humans, so we use high-level programming languages instead.
What is programming?
Programming is the process of providing a computer with a set of instructions in a particular language that it can understand to perform tasks.
How does one improve at programming?
Programming is a skill that improves with practice. The more you write code, the better you become at applying logic and conditions.
Why is programming considered a creative skill?
Programming is creative because there are many different ways to solve problems through coding.
What are constants and variables in programming?
Constants and variables allow you to store and organize values of the same type. Variables can change values, while constants cannot.
Example in Swift:
let pi = 3.14
var age = 25
How do you declare a constant in Swift?
You declare a constant using the keyword ‘let’ followed by the constant name, assignment operator ‘=’, and a value.
Example:
let pi = 3.14
How do you declare a variable in Swift?
You declare a variable using the keyword ‘var’ followed by the variable name, assignment operator ‘=’, and a value.
Example:
var age = 25
Why can’t a constant’s value be changed in Swift?
A constant’s value can’t be changed because it’s declared as a fixed value with the ‘let’ keyword, which makes it immutable.
Why would you use a variable instead of a constant?
You would use a variable if the value needs to change over time, such as storing a user’s age, which changes annually.
What happens if you declare two variables with the same name?
If you declare two variables or constants with the same name, Swift will produce an error.
What naming restrictions exist for Swift variables and constants?
Variable and constant names cannot start with a number or use mathematical symbols.
What are data types in Swift?
Data types describe the type of value a variable or constant will store, such as integers, floats, Booleans, and strings.
What is an integer in Swift?
An integer represents whole numbers, and its type is ‘Int’.
Example:
let numberOfItems = 10
What is a floating point in Swift?
A floating point represents numbers with a decimal, and its type is ‘Float’ or ‘Double’ for more precision.
Example:
let price = 19.99