• 카테고리

    질문 & 답변
  • 세부 분야

    프로그래밍 언어

  • 해결 여부

    미해결

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

22.07.08 00:44 작성 조회수 129

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.