Predeclared Types and Declarations Flashcards

1
Q

What are the predeclared types in Go?

A

Booleans, integers, floats, and strings.

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

What is the zero value in Go?

A

The default value for an uninitialized variable.

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

What are literals in Go?

A

Untyped values like numbers, characters, and strings.

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

How are integer literals written in Go?

A

In base 10, with optional underscores (e.g., 1_234).

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

What are the two types of string literals in Go?

A

Interpreted (double quotes) and raw (backticks).

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

What values can a boolean have in Go?

A

true and false.

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

What is the zero value for a boolean in Go?

A

false.

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

What are some integer types in Go?

A

int8, int16, int32, int64, uint8, uint16, uint32, uint64, byte (uint8), int, uint.

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

What is the zero value for an integer in Go?

A

0.

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

How does division work with integers in Go?

A

It truncates towards zero.

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

What are the floating-point types in Go?

A

float32 and float64.

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

Why avoid == and != with floating-point numbers in Go?

A

Precision issues can cause unexpected results.

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

What is the zero value for a string in Go?

A

”” (empty string).

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

Are strings mutable in Go?

A

No, they are immutable.

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

What is a rune in Go?

A

An alias for int32, representing a Unicode code point.

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

Is type conversion automatic in Go?

A

No, it must be explicit.

17
Q

What’s the difference between var and := in Go?

A

var declares variables with optional initializers; := is a short declaration with type inference, used in functions.

18
Q

What can be declared with const in Go?

A

Compile-time values like literals, true/false, strings, and runes.

19
Q

What is an untyped constant in Go?

A

A constant with no specific type, allowing flexible use.

20
Q

What happens to unused local variables in Go?

A

They cause a compile-time error.