강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

Youngwook Kim님의 프로필 이미지
Youngwook Kim

작성한 질문수

쉽고 빠르게 끝내는 GO언어 프로그래밍 핵심 기초 입문 과정

변수 및 상수

짧은 선언으로 변수 여러개를 만들때

작성

·

238

0

a, b := 1, 2
a2, b := 3, 4

b변수 중복선언 에러가 날것 같은데,
b변수에 4가 대입되는 이유는 무었인가요?

 

답변 1

0

좋은사람님의 프로필 이미지
좋은사람
지식공유자

안녕하세요.

짧은 선언(Short Variable Declaration) 질문을 주셨네요.

 

짧은 선언에서는 같은 블록에서 공백이 아닌 새 변수를 다시 선언 가능해요.

단, 짧은 선언에서만 가능합니다. 원본 값은 지워지고 새 할당하겠죠?

 

Unlike regular variable declarations, a short variable declaration may redeclare variables provided they were originally declared earlier in the same block with the same type, and at least one of the non-blank variables is new. As a consequence, redeclaration can only appear in a multi-variable short declaration. Redeclaration does not introduce a new variable; it just assigns a new value to the original.

Youngwook Kim님의 프로필 이미지
Youngwook Kim

작성한 질문수

질문하기