SW

c언어 배열 사이즈와 데이터 확인 방법

S.Zinlee 2016. 7. 25. 21:38
 
#include <stdio.h>

void trot(int trots[], int n);

void main()
{
    int aa[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
    int size = sizeof(aa) / sizeof(*aa); // 전체크기 / 원소크기 = 원소개수

    printf("size of %d\n", size);
    trot(aa, size);
}

void trot(int trots[], int n)
{
    int i;

    for(i = 0; i < n; i++)
        printf("%d\n", trots[i]);
}