Basic Types and Variables Flashcards

1
Q

What are the main technological areas that have seen significant advancements over the past 20 years?

A

Mobile devices, the cloud, artificial intelligence, and self-driving cars.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What was the analytical engine?

A

The analytical engine was an early computing device that used mechanical gears and was computed by manually moving hand cranks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is binary code?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why do computers use binary code?

A

Computers only understand binary code because it represents two states (on and off) which are easy to represent with electrical signals.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is an example of decimal to binary conversion?

A

Decimal 1 is binary 1, Decimal 2 is binary 10, Decimal 3 is binary 11.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the CPU?

A

The CPU, or Central Processing Unit, is the brain of the computer that processes instructions and performs calculations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What happens when a program is written in any language?

A

It needs to be compiled or interpreted into machine-readable code (binary) so that the computer can execute it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Why don’t humans program in binary?

A

Binary code is hard to read and error-prone for humans, so we use high-level programming languages instead.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is programming?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How does one improve at programming?

A

Programming is a skill that improves with practice. The more you write code, the better you become at applying logic and conditions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Why is programming considered a creative skill?

A

Programming is creative because there are many different ways to solve problems through coding.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are constants and variables in programming?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you declare a constant in Swift?

A

You declare a constant using the keyword ‘let’ followed by the constant name, assignment operator ‘=’, and a value.
Example:
let pi = 3.14

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you declare a variable in Swift?

A

You declare a variable using the keyword ‘var’ followed by the variable name, assignment operator ‘=’, and a value.
Example:
var age = 25

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Why can’t a constant’s value be changed in Swift?

A

A constant’s value can’t be changed because it’s declared as a fixed value with the ‘let’ keyword, which makes it immutable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Why would you use a variable instead of a constant?

A

You would use a variable if the value needs to change over time, such as storing a user’s age, which changes annually.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What happens if you declare two variables with the same name?

A

If you declare two variables or constants with the same name, Swift will produce an error.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What naming restrictions exist for Swift variables and constants?

A

Variable and constant names cannot start with a number or use mathematical symbols.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What are data types in Swift?

A

Data types describe the type of value a variable or constant will store, such as integers, floats, Booleans, and strings.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is an integer in Swift?

A

An integer represents whole numbers, and its type is ‘Int’.
Example:
let numberOfItems = 10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is a floating point in Swift?

A

A floating point represents numbers with a decimal, and its type is ‘Float’ or ‘Double’ for more precision.
Example:
let price = 19.99

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is the difference between ‘Float’ and ‘Double’ in Swift?

A

A ‘Float’ has 32 bits of storage for representing numbers, while a ‘Double’ has 64 bits, allowing it to represent larger numbers.

23
Q

What is the Boolean data type?

A

A Boolean data type represents logical values: true or false.
Example:
let isAuthenticated = true

24
Q

What is type inference in Swift?

A

Type inference means Swift can automatically determine the data type based on the value assigned to a variable or constant.
Example:
let score = 100 (Swift will infer ‘score’ is of type Int).

25
Q

What does it mean that Swift is a type-safe language?

A

Type safety in Swift means you cannot mix different data types, and Swift checks data types before compiling the code to avoid errors.

26
Q

What are operators in programming?

A

Operators are used to perform operations on variables and values, manipulating data and returning results.
Example in Swift:
let sum = 5 + 3 // sum equals 8

27
Q

What is the assignment operator?

A

The assignment operator ‘=’ assigns a value to a variable.
Example in Swift:
var age = 25

28
Q

What are mathematical operators in Swift?

A

Mathematical operators include addition (+), subtraction (-), multiplication (*), and division (/).
Example in Swift:
let result = 5 * 3 // result equals 15

29
Q

What is a compound assignment operator?

A

Compound assignment operators are shorthand for operations. For example, instead of writing ‘x = x + 2’, you can write ‘x += 2’.
Example in Swift:
var count = 5
count += 2 // count equals 7

30
Q

What is the modulus operator?

A

The modulus operator (%) returns the remainder of a division.
Example in Swift:
let remainder = 10 % 3 // remainder equals 1

31
Q

How does Swift handle floating point arithmetic?

A

Swift automatically assigns floating point numbers to the Double type.
Example in Swift:
let value = 3.3 + 1.5 // value equals 4.8

32
Q

What is the unary minus operator in Swift?

A

The unary minus operator allows you to convert a number from positive to negative and vice versa.
Example in Swift:
let negative = -5 // negative equals -5

33
Q

What is numeric type conversion in Swift?

A

Numeric type conversion allows you to change the type of a variable to combine different types (e.g., Int and Double).
Example in Swift:
let sum = Double(5) + 0.3 // sum equals 5.3

34
Q

Why can’t different numeric types be added together in Swift?

A

Swift is a strongly typed language, meaning different types (e.g., Int and Double) can’t be combined without conversion.
Example:
let sum = Double(5) + 0.3

35
Q

What is BIDMAS in Swift?

A

BIDMAS stands for Brackets, Indices, Division, Multiplication, Addition, and Subtraction. It represents the order of operations Swift follows for mathematical expressions.
Example:
let result = (2 + 3) * 4 // result equals 20

36
Q

What are operators in programming?

A

Operators are used to perform operations on variables and values, manipulating data and returning results.
Example in Swift:
let sum = 5 + 3 // sum equals 8

37
Q

What is the assignment operator?

A

The assignment operator ‘=’ assigns a value to a variable.
Example in Swift:
var age = 25

38
Q

What are mathematical operators in Swift?

A

Mathematical operators include addition (+), subtraction (-), multiplication (*), and division (/).
Example in Swift:
let result = 5 * 3 // result equals 15

39
Q

What is a compound assignment operator?

A

Compound assignment operators are shorthand for operations. For example, instead of writing ‘x = x + 2’, you can write ‘x += 2’.
Example in Swift:
var count = 5
count += 2 // count equals 7

40
Q

What is the modulus operator?

A

The modulus operator (%) returns the remainder of a division.
Example in Swift:
let remainder = 10 % 3 // remainder equals 1

41
Q

How does Swift handle floating point arithmetic?

A

Swift automatically assigns floating point numbers to the Double type.
Example in Swift:
let value = 3.3 + 1.5 // value equals 4.8

42
Q

What is the unary minus operator in Swift?

A

The unary minus operator allows you to convert a number from positive to negative and vice versa.
Example in Swift:
let negative = -5 // negative equals -5

43
Q

What is numeric type conversion in Swift?

A

Numeric type conversion allows you to change the type of a variable to combine different types (e.g., Int and Double).
Example in Swift:
let sum = Double(5) + 0.3 // sum equals 5.3

44
Q

Why can’t different numeric types be added together in Swift?

A

Swift is a strongly typed language, meaning different types (e.g., Int and Double) can’t be combined without conversion.
Example:
let sum = Double(5) + 0.3

45
Q

What is BIDMAS in Swift?

A

BIDMAS stands for Brackets, Indices, Division, Multiplication, Addition, and Subtraction. It represents the order of operations Swift follows for mathematical expressions.
Example:
let result = (2 + 3) * 4 // result equals 20

46
Q

What is a string in Swift?

A

A string is an ordered collection of characters surrounded by double quotes and is represented by the String type.
Example in Swift:
let greeting = “Hello, World!”

47
Q

What is a string literal?

A

A string literal is the actual group of characters inside double quotes.
Example in Swift:
let myString = “Hello, World!” // “Hello, World!” is the string literal

48
Q

What is string mutability in Swift?

A

If a string is assigned to a constant (let), it is immutable and can’t be changed. If assigned to a variable (var), it is mutable and can be changed.
Example:
var message = “Hi”
message = “Hello” // This works because it’s a variable

49
Q

How can you concatenate strings in Swift?

A

You can concatenate (combine) two strings using the + operator.
Example in Swift:
let firstName = “John”
let lastName = “Doe”
let fullName = firstName + “ “ + lastName // “John Doe”

50
Q

How can you compare strings in Swift?

A

You can compare strings using methods like hasPrefix and hasSuffix, which check if a string starts or ends with specific characters.
Example in Swift:
let greeting = “Hello, World!”
greeting.hasPrefix(“Hello”) // true

51
Q

How can you convert strings to uppercase or lowercase in Swift?

A

You can use the uppercased() and lowercased() methods to convert a string to all uppercase or all lowercase characters.
Example in Swift:
let text = “Hello”
let upper = text.uppercased() // “HELLO”

52
Q

How can you count the number of characters in a string?

A

You can use the count method to find the number of characters in a string.
Example in Swift:
let message = “Hi There”
let characterCount = message.count // 8

53
Q

What are multiline string literals in Swift?

A

Multiline string literals allow you to store multiple lines of text using three double-quotes (“””).
Example:
let message = “””
This is a multiline string.
It spans several lines.
“””