대입연산자(=)
대입 연산자(=)는 우변의 결과값을 좌변의 변수에 복사됩니다.
우변이 기본타입 값이면 값이 좌변변수에 복사됩니다.
int x = 10;
System.out.println(x); // 10 출력
우변이 연산을 포함한 표현식이면 결과값이 좌변변수에 복사됩니다.
int y = 1 + 2;
System.out.println(y); // 3 출력
우변이 변수이면 좌변변수에 들어있는 값이 복사됩니다.
int a = 10;
int b = a;
System.out.println(b); // 10 출력
우변의 값이 참조타입값(or참조변수)이면 참조값이 좌변에 복사됩니다.
배열 참조 타입은 이후 강좌에서 설명한다. 지금은 그냥 참조값이 좌변으로 복사된다는 것만 알고 지나가면 됩니다.
int[] arr = [1,2,3];
System.out.println{arr}; // 참조값이 출력
1 2 3 4 5 6 7 8 9 10 11 12 13 | public class Ex7_1 { public static void main(String[] args) { int x = 10; System.out.println(x); int y = 1 + 2; System.out.println(y); int a = 10; int b = a; System.out.println(b); int[] arr = {1,2,3}; System.out.println(arr); } } | cs |
실행결과
1 2 3 4 | 10 3 10 [I@15db9742 | cs |
'6. 연산자' 카테고리의 다른 글
0) 문자열 연산 프로그램 만들어 보기 (0) | 2016.10.12 |
---|---|
0) 연산(4칙연산) 프로그램 만들어 보기 (0) | 2016.10.11 |