Go

Go Basics

Variables, constants, basic types, functions, packages, imports, control flow, defer

25 면접 질문·
Junior
1

What is the correct syntax to declare a variable in Go?

답변

In Go, there are three main ways to declare a variable: var x int (explicit declaration with type), var x = 10 (declaration with type inference), and x := 10 (short declaration with inference, only inside functions). The short form := is most commonly used for local variables as it is concise and idiomatic.

2

What is the zero value of an int variable in Go?

답변

In Go, all variables are initialized with a zero value by default if no value is provided during declaration. For numeric types (int, float64), the zero value is 0. For booleans it's false, for strings it's an empty string, and for pointers it's nil. This behavior ensures there are never uninitialized variables in Go.

3

What is the difference between var x int and x := 0 in Go?

답변

var x int declares a variable with zero value (0) and an explicit type, while x := 0 uses short declaration with type inference. The short declaration := can only be used inside functions, while var can be used at package level. The := form is preferred for local variables as it is more concise and idiomatic.

4

How to declare a constant in Go?

5

What are the basic numeric types in Go?

+22 면접 질문

다음 면접을 위해 Go을 마스터하세요

모든 질문, flashcards, 기술 테스트, 코드 리뷰 연습, 면접 시뮬레이터에 접근하세요.

무료로 시작하기