To declare an integer array in C, you can use array notation or dynamic memory allocation.
In this example,
numbers
with predefined values using array notation.#include <stdio.h>
int main() {
int numbers[5] = {1, 2, 3, 4, 5};
printf("Integer Array: %d, %d, %d, %d, %d\n", numbers[0], numbers[1], numbers[2], numbers[3], numbers[4]);
return 0;
}
Integer Array: 1, 2, 3, 4, 5
In this example,
emptyArray
using dynamic memory allocation.#include <stdio.h>
#include <stdlib.h>
int main() {
int *emptyArray = (int*)malloc(0 * sizeof(int));
printf("Empty Integer Array:\n");
free(emptyArray);
return 0;
}
Empty Integer Array:
In this tutorial, we learned How to Declare an Integer Array in C language with well detailed examples.