In C, you can check if an array is empty by comparing its length or size with 0.
In this example,
numbers
with some elements.isEmpty
.#include <stdio.h>
int main() {
int numbers[] = {1, 2, 3};
int size = sizeof(numbers) / sizeof(numbers[0]);
int isEmpty = size == 0;
printf("Array is empty: %s\n", isEmpty ? "true" : "false");
return 0;
}
Array is empty: false
In this example,
emptyArray
.isEmpty
.#include <stdio.h>
int main() {
int emptyArray[0];
int size = sizeof(emptyArray) / sizeof(emptyArray[0]);
int isEmpty = size == 0;
printf("Array is empty: %s\n", isEmpty ? "true" : "false");
return 0;
}
Array is empty: true
In this tutorial, we learned How to check if an Array is Empty in C language with well detailed examples.