Arrays

what?

 

An array is a sequential collection of variables of the same data type/ it stores data elements in a continuous memory location. A string is a sequence of characters. In other words, we can say that string is an array of the character data type. You will get an overview of how to approach and implement them.

 

한줄 정리 : 배열은 연속적인 값(문자열, 숫자)이며, 같은 타입의 데이터를 가진다. 

how?

int arr[5] = {1,2,3,4,5}

1. int는 데이터의 타입을 의미함. integer은 정수에서 편리함을 위해 "eger"을 생략함.

2. arr는 배열의 이름을 뜻함. 

3. [ ]안에 숫자는 데이터의 크기를 뜻함. Equle 오른 쪽을을 보면, 5개의 데이터가 저장되어 있음.

4. 배열에는 인덱스라는 개념이 있음. 인덱스는 사실 포인터라는 개념도 같이 포함되어 "0"부터 숫자 세기를 시작함.   따라서, arr[0]은 1이고 arr[1]은 2임.

 

예시 :

5,4,12,7,15,9 배열을 거꾸로 출력해라. (단, 5는 출력하면 안된다.)

 

var rarr:[Int] = [5,4,12,7,15,9]

for i in rarr.reversed(){

if i == 5

{

break

}

else

{

print(i)

}

}

 

var rarr:[Int] = [5,4,12,7,15,9]

for i in rarr.reversed()[...4]{

print(i)

}

 

 

Strings

what?

A string is a sequence of characters. In other words, a string is an array of character data type. An instance of a string is called a string literal

 

한줄 정리: 연속된 문자

예시 : 

 

let str = "Hello world"

 

시작 시간: 2:53 ~ 4:49

 

 

참고:

이 글은 Codemonk의 배열 그리고 문자열을 공부하는 내용을 정리하는 것을 목적으로 합니다.

www.hackerearth.com/practice/codemonk/

 

+ Recent posts