code to print out entire array in c

#include <stdio.h>

#define SIZE 5

int main() {
    int arr[SIZE] = {1, 2, 3, 4, 5};
    int i;

    printf("Elements of the array are: ");

    for (i = 0; i < SIZE; i++) {
        printf("%d ", arr[i]);
    }

    return 0;
}

Explanation:

  • #include <stdio.h>: This line includes the standard input-output header file in the program, allowing the use of functions like printf() and scanf().

  • #define SIZE 5: This line defines a constant named SIZE with a value of 5. It helps in setting the size of the array.

  • int main() { ... }: This is the main function where the program execution begins.

  • int arr[SIZE] = {1, 2, 3, 4, 5};: This line declares an integer array named arr with a size of SIZE (which is 5 in this case) and initializes it with values 1, 2, 3, 4, and 5.

  • int i;: This declares an integer variable i which will be used as a loop counter.

  • printf("Elements of the array are: ");: This line prints a message to indicate that the following output will be the elements of the array.

  • for (i = 0; i < SIZE; i++) { ... }: This is a for loop that iterates through each element of the array from index 0 to SIZE - 1.

  • printf("%d ", arr[i]);: Inside the loop, this line prints each element of the array using the %d format specifier for integers and arr[i] to access each element of the array.

  • return 0;: This statement signifies the end of the main() function and returns an exit status of 0, indicating successful execution of the program.