본문 바로가기

C언어/함수설명&Tip

sizeof 연산자로 배열의 행과 열 크기를 알아내는 팁

int main(int argc, char **argv) 
{ 
    int a[5][10]; 
 
    printf("rows : %d\n",sizeof(a)/sizeof(a[0])); 
    printf("cols : %d\n", sizeof(a[0])/sizeof(int)); 
    return 0; 
} 
 
실행결과
$ ./sizeof 
rows : 5 
cols : 10