본문 바로가기
[알아두면 좋을 것들]

C 배열 초기화

by Hevton 2021. 3. 7.
반응형
#include <stdio.h>

int main() {
    
    int arr[5] = {0, };
    
    for(int i = 0; i < 5; i++) {
        printf("%d ", arr[i]);
    }
}
/*
 Output : 0 0 0 0 0 0
 */

#include <stdio.h>

int main() {
    
    int arr[5] = {1, 2};
    
    for(int i = 0; i < 5; i++) {
        printf("%d ", arr[i]);
    }
}
/*
 Output : 1 2 0 0 0 0
 */

#include <stdio.h>

int main() {
    
    int arr[5] = {1, 2, };
    
    for(int i = 0; i < 5; i++) {
        printf("%d ", arr[i]);
    }
}
/*
 Output : 1 2 0 0 0 0
 */

#include <stdio.h>

int main() {
    
    int arr[5] = {-1, };
    
    for(int i = 0; i < 5; i++) {
        printf("%d ", arr[i]);
    }
}
/*
 Output : -1 0 0 0 0 0
 */
반응형