배열, 문자열 배열로 다루기
C
#include <stdio.h>
int main() {
//초기화 안하고 출력한 경우
int arr[10];
for(int i=0;i<10;i++){
printf("%d\n",arr[i]);
}
//일부 값 초기화하기
int arr2[10] = {1,2};
for(int i=0;i<10;i++){
printf("%d\n",arr2[i]);
}
int arr3[] = {1,2,3};
printf("%ld\n", sizeof(arr3)/sizeof(int));
//실수형 배열 초기화
float arr_f[5] = {1.1, 2.2, 3.3, 4.4, 5.5};
for(int i=0;i<5;i++){
printf("%.1f\n",arr_f[i]);
}
//문자열 다루기
char c ='A';
printf("%c\n",c);
char str[7] = "coding";
printf("%s\n",str);
char str2[] = "coding";
printf("%ld\n",sizeof(str2));
for(int i=0;i<7;i++){
printf("%c\n",str2[i]);
}
//배열에 한글 저장하기
char kor[] = "알고학원"
printf("%s\n",kor);
printf("%ld\n",sizeof(kor));
}
Output
Embed on website
To embed this program on your website, copy the following code and paste it into your website's HTML:
Comments
This comment belongs to a banned user and is only visible to admins.
This comment belongs to a deleted user and is only visible to admins.