In C, you declare an array by specifying the type and size of the array.
In this example,
numbers
of type int
and size 5
.#include <stdio.h>
int main() {
int numbers[5] = {1, 2, 3, 4, 5};
for(int i = 0; i < 5; i++) {
printf("%d ", numbers[i]);
}
return 0;
}
1 2 3 4 5
In this example,
chars
of type char
and size 6
.#include <stdio.h>
int main() {
char chars[6] = {'a', 'b', 'c', 'd', 'e', '\0'};
printf("%s", chars);
return 0;
}
abcde
In this tutorial, we learned How to Declare an Array in C language with well detailed examples.