Intelligence Modeling Lab.
School of Information and Communication Engineering, Sungkyunkwan University컴퓨터공학실습 1
Part 2
Ch1. 1 차원 배열이란 무엇인가
2011-04-14
1Intelligence Modeling Lab.
School of Information and Communication Engineering, Sungkyunkwan University목차
1 차원 배열이란
1 차원 배열의 주소와 값의 참조
Intelligence Modeling Lab.
School of Information and Communication Engineering, Sungkyunkwan University1 차원 배열이란
배열이란 ?
◦
같은 자료형을 가진 연속된 메모리 공간으로 이루어진 자료
구조
◦
같은 자료형의 변수가 여러 개 필요할 때 사용
(char, int, double, etc.)
◦
학생 성적 , 도서 목록 , 달력 등
Intelligence Modeling Lab.
School of Information and Communication Engineering, Sungkyunkwan University1 차원 배열이란
배열의 선언
( 자료형 : 배열의 자료형 ,
배열 이름 : 배열의 이름 ,
[ 배열 길이 ]: 배열 요소의 총 길이 )
4Intelligence Modeling Lab.
School of Information and Communication Engineering, Sungkyunkwan University1 차원 배열이란
배열의 데이터 저장 / 참조
Intelligence Modeling Lab.
School of Information and Communication Engineering, Sungkyunkwan University1 차원 배열이란
배열의 초기화
6int array1[5] = {90,80,70,60,50};
int array2[ ] = {90,80,70,60,50};
int array3[5] = {90,80,70};
Intelligence Modeling Lab.
School of Information and Communication Engineering, Sungkyunkwan University1 차원 배열이란
배열 선언 시 주의점
◦
배열 요소는 0 부터 시작
◦
배열 초기화를 중괄호로 할 경우 선언과 동시에 초기화
◦
배열의 길이는 상수만 지정 가능 ( 변수로 지정 불가 )
7Intelligence Modeling Lab.
School of Information and Communication Engineering, Sungkyunkwan University1 차원 배열의 주소와 값의 참조
& 연산자는 주소를 참조하는 연산자이다
8변수의 주소 표현
배열의 주소 표현
사용법 :
&
변수이름
사용법 :
&
배열 요소의 위치
int a=10, b=20;
printf(“
%x
\n”,
&a
);
// a
의 주
소
printf(“
%x
\n”,
&b
);
// b
의 주
소
int array[2] = {10, 20};
printf(“
%x
\n”,
&array[0]
);
// array[0]
의
주소
printf(“
%x
\n”,
&array[1]
);
// array[1]
의
주소
int
ar-ray1[3]
char
ar-ray2[3]
Intelligence Modeling Lab.
School of Information and Communication Engineering, Sungkyunkwan University1 차원 배열의 주소와 값의 참조
배열의 이름은 배열의 시작 주소이다
Intelligence Modeling Lab.
School of Information and Communication Engineering, Sungkyunkwan University1 차원 배열의 주소와 값의 참조
* 연산자는 메모리 공간에 저장된 값을 참조한다
10변수의 값 참조
배열 요소의 값 참조
사용법 :
*
&
변수이름
사용법 :
*
&
배열 요소
int a=10, b=20;
printf(“
%d
\n”,
*&a
);
// a
의
값
printf(“
%d
\n”,
*&b
);
// b
의 값
int array[2] = {10, 20};
printf(“
%d
\n”,
*&array[0]
);
// array[0]
의 값
printf(“
%d
\n”,
*&array[1]
);
// array[1]
의 값
Intelligence Modeling Lab.
School of Information and Communication Engineering, Sungkyunkwan University1 차원 배열의 주소와 값의 참조
Intelligence Modeling Lab.
School of Information and Communication Engineering, Sungkyunkwan University1 차원 배열의 주소와 값의 참조
요약
12