How to Print an Array in C?

Use a loop to access each element of the array

Print each element with `printf`

Example for an integer array:

`int arr[] = {1, 2, 3, 4, 5};`

`int n = sizeof(arr) / sizeof(arr[0]);`

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

Example for a character array:

`char str[] = “Hello”;`

`printf(“%s”, str);`

Suggested for You

Trending Today