Karteikarten
Predeclared Types and Declarations
Karten in diesem Stapel (20)
- 1What value does Go assign to variables declared without an initial value?The default zero value.
- 2What is a literal in Go?An explicitly specified number, character, or string.
- 3What prefixes are used for binary, octal, and hexadecimal integer literals in Go?Binary: 0b, Octal: 0o, Hexadecimal: 0x.
- 4Can underscores be used in numeric literals for readability?Yes, but not at the beginning, end, or next to each other.
- 5What is the default type for floating-point literals in Go?float64.
- 6How are rune literals represented in Go?Surrounded by single quotes, can be Unicode characters or escaped sequences.
- 7What are the two types of string literals in Go and how do they differ?Interpreted strings (use double quotes, interpret rune literals) and raw strings (use backquotes, contain characters as is).
- 8What is the default value of the bool type in Go?false.
- 9What is the difference between byte and int in Go?byte is an alias for uint8, and int is platform-dependent (32-bit or 64-bit).
- 10When should you use specific integer types versus int?Use specific types for binary files/protocols, generics for libraries, otherwise use int.
- 11Why should you avoid using == and != for floating-point comparisons?Due to precision issues.
- 12What is the zero value for strings in Go?The empty string.
- 13What is a rune in Go?An alias for int32, used for characters.
- 14How does Go handle type promotion?There is no automatic type promotion; explicit type conversion is required.
- 15What are the two ways to declare variables in Go, and when should each be used?var (for declaring multiple variables, with or without initial values) and := (for short declaration and assignment within functions).
- 16What is a key restriction on using const in Go?const can only hold compile-time values.
- 17What is the difference between typed and untyped constants?Untyped constants behave like literals with a default type, while typed constants can only be assigned to variables of the same type.
- 18What happens if you declare local variables in Go but do not use them?It causes a compile-time error.
- 19What are the rules for naming identifiers in Go?Must start with a letter or underscore, can contain letters, numbers, and underscores.
- 20What naming convention is used for package-level declarations in Go?Camel case (e.g., indexCounter, numberTries), with accessibility determined by the case of the declaration.
Informationen
- Beschreibung
- Book Learning Go (CH2: Predeclared Types and Declarations) Karteikarten am Predeclared Types and Declarations, erstellt von Filipi Melo am 31/07/2024.
- Erstellt von
- Filipi Melo
- Aufrufe
- 2
- Bewertung