Study Group/빡공단 30기
[Day 15] How to use one-dimensional array
Fllbert
2023. 1. 17. 18:04

In this class, I learned about one-dimensional array for containing the values.
Unlike general variables, one-dimensional arrangement can be accessed through an index to each space.
For example, if you declare five variables, each variable must be defined with a specific value.
However, if you declare a 1D array with five spaces only once, each value can be accessed through an index.
/* General Variables */
int A1 = 10;
int A2 = 20;
int A3 = 30;
int A4 = 40;
int A5 = 50;
/* One-dimensional Array */
int A[5] = {10, 20, 30, 40, 50};
In case of charater array, string values can be seperated by each letter with indexing.
/* General Variables */
char Char1 = 'H';
char Char2 = 'E';
char Char3 = 'L';
char Char4 = 'L';
char Char5 = 'O';
printf("%c \n", Char1);
printf("%c \n", Char2);
printf("%c \n", Char3);
printf("%c \n", Char4);
printf("%c \n", Char5);
/* One-dimensional Array */
char Str[6] = "HELLO";
printf("%s \n", Str);
printf("%c \n", Str[0]);
printf("%c \n", Str[1]);
printf("%c \n", Str[2]);
printf("%c \n", Str[3]);
printf("%c \n", Str[4]);