Terms Flashcards

1
Q

Statically typed

A

Data type of each variable must be known at compile time.

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

What are Rusts four primary scalar types?

A

Integers, Floating points, Characters, Booleans.

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

What is an integer data type?

A

A number without a fractional part.

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

What is a panic() in rust?

A

When a program exits with an error.

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

How does Rust handle integer overflow?

A

At runtime when debugging: it panics() At runtime on release, it wraps (i.e., from 255 -> 1).

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

What memory does a Boolean value take up?

A

One byte, nom.

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

How are character literals differentiated from string literals in Rust?

A

Strings use double quotes, characters use single quotes.

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

What is an approximate CS definition of a tuple?

A

An immutable ordered sequence of elements.

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

How do arrays differ from tuples in Rust?

A

They are declared with square brackets instead of round, all elements are of the same data type.

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

What is the difference between a statement and an expression?

A

A statement is an instruction to perform some action, whereas an expression evaulates code to a resulting value.

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

What happens at the e.o.l with a statement or expression in Rust?

A

Statements end in a semi colon, expressions do not.

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

What is the difference between shadowing and mutability?

A

When a mutable variable is modified, the value in memory is modified. When an immutable variable is shadowed, a new memory location is used to store a new value - with the variable name. The old memory location is unused.

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

What kind of loops does Rust have?

A

while, for, loop

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

What is the stack?

A

A memory structure that is strictly first in last out. Push onto stack, or pop off the stack.

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

What is the heap?

A

A memory structure that allows “random” storage and retrieval of allocations.

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

What is allocating on the heap?

A

Find an empty (and large enough) space on the heap, mark it as being used, and return a pointer to that location.

17
Q

Is pushing onto the stack or allocating on the heap faster?

A

Pushing on the stack!

18
Q

What calling a function with arguments, what memory structure is used?

A

The stack. Any arguments and local variables are pushed onto the stack.

19
Q

What is boilerplate code?

A

Refers to code that must be include with little to no alteration.

20
Q

What is verbose code?

A

Containing more explanation than necessary, or more code than necessary.

21
Q

What is meant by a string “literal”?

A

Text that is hard coded in the program.

22
Q

What is RAII?

A

Resource allocation is initialization. The curly bracket at the end of a code block automatically drops any variables that go out of scope from memory.

23
Q

Will this code run? Why?

fn main() {

let hello = String::from(“hi”);

say_hi(hello);

println!(“saying {} again”, hello);

}

fn say_hi(hello: String) {

println!(“{}”, hello);

}

A

Nope, because hello is moved to the scope of say_hi and not returned. Once a variable-value binding goes out of scope it is dropped from memory.

24
Q

What is a String slice?

A

A reference to a part of a string! Initialized and declared with:

&s[0..5]

Where the brackets contain the index range (upper bound exclusive).

25
Q

How can the length of a string be found?

A

Using:

variable_name.len()