Qaupot Blog
Software Engineering, Trip

Array

Array๋Š” ๊ณ ์ •๋œ ํฌ๊ธฐ๋ฅผ ๊ฐ€์ง€๋Š” ์„ ํ˜•์˜ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์˜๋ฏธํ•ฉ๋‹ˆ๋‹ค. ํฌ๊ธฐ์˜ ๋ณ€ํ™”๊ฐ€ ๋ฐœ์ƒํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์–ผ๋งˆ๋‚˜ ์‚ฌ์šฉํ•  ๊ฒƒ์ธ์ง€ ๊ณ„ํš๋œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์—์„œ ์‚ฌ์šฉํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

์ด ์ปจํ…Œ์ด๋„ˆ๋Š” ๋‹ค๋ฅธ ์ปจํ…Œ์ด๋„ˆ๋“ค์˜ ๊ธฐ๋ณธ์ด ๋˜๋Š” ์ปจํ…Œ์ด๋„ˆ ์ค‘ ํ•˜๋‚˜์ด๋ฉฐ, ๊ฐ€์žฅ ๊ฐ„๋‹จํ•˜๋ฉด์„œ๋„ ๊ฐ•๋ ฅํ•ฉ๋‹ˆ๋‹ค. ๋ฉ”๋ชจ๋ฆฌ ์ฃผ์†Œ์— ์˜ํ•ด Array๋‚ด๋ถ€์˜ ์–ด๋””๋“ ์ง€ ํ•œ๋ฒˆ์— ์ฐพ์„ ์ˆ˜ ์žˆ์œผ๋ฉฐ (Random Access), ํฌ๊ธฐ ๋ณ€ํ™”์— ์˜ํ•œ ์žฌ ํ• ๋‹น์„ ํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ์ถ”๊ฐ€์ ์ธ ๋น„์šฉ์ด ์†Œ๋ชจ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

C / C++์—์„œ๋Š” ์ผ๋ฐ˜์ ์œผ๋กœ ๋ฐฐ์—ด์„ ์˜๋ฏธํ•˜๋ฉฐ, Standard template library์—์„œ๋Š” array ํ—ค๋”์— array ํ…œํ”Œ๋ฆฟ ํด๋ž˜์Šค๋กœ ๊ตฌํ˜„๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค.

#include <stdio.h>
int main(int argc, char** argv)
{
    int array[6];
    array[3] = 2;

    for (int val : array)
    {
        printf("%d\n", val);
    }
    return 0;
}

๋ฐฐ์—ด์„ ์ด์šฉํ•œ Array์ปจํ…Œ์ด๋„ˆ ์˜ˆ์ œ ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค.

#include <iostream>
#include <array>
int main(int argc, char** argv)
{
    std::array<int, 6> array;
    array[3] = 2;

    for (int val : array)
    {
        printf("%d\n", val);
    }
    return 0;
}

array template class๋ฅผ ์ด์šฉํ•œ ์˜ˆ์ œ ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค. arrayํด๋ž˜์Šค์— ๋Œ€ํ•œ ๋ณด๋‹ค ์ž์„ธํ•œ ๊ตฌ์„ฑ์€ ๋‹ค๋ฅธ STL reference๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ•ด ์ฃผ์„ธ์š”.

์ด ๋ธ”๋กœ๊ทธ๋Š” ๊ฐœ์ธ ๋ธ”๋กœ๊ทธ์ž…๋‹ˆ๋‹ค. ๊ฒŒ์‹œ๊ธ€์€ ์˜ค๋ฅ˜๋ฅผ ํฌํ•จํ•˜๊ณ  ์žˆ์„ ์ˆ˜ ์žˆ์ง€๋งŒ, ์ €์ž๋Š” ์˜ค๋ฅ˜๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ๋…ธ๋ ฅํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
๊ฒŒ์‹œ๊ธ€์— ๋ณ„๋„์˜ ๊ณ ์ง€๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ, ํฌ๋ฆฌ์—์ดํ‹ฐ๋ธŒ ์ปค๋จผ์ฆˆ ์ €์ž‘์žํ‘œ์‹œ-๋น„์˜๋ฆฌ-๋ณ€๊ฒฝ๊ธˆ์ง€ 4.0 ๋ผ์ด์„ ์Šค๋ฅผ ๋”ฐ๋ฆ…๋‹ˆ๋‹ค.

This blog is personal blog. published posts may contain some errors, but author doing efforts to clear errors.
If post have not notice of license, it under creative commons Attribution-NonCommercial-NoDerivatives 4.0.