OneBite.Dev - Coding blog in a bite size

check if array is empty in C

Code snippet on how to check if array is empty in C

  int arr[SIZE], size;

// Check if array is empty
if (size == 0)
  printf("Array is empty");
else
  printf("Array is not empty");

This code starts by creating an array called arr with a size of SIZE. We also create an integer called size. Next, an if statement is used to check if the size of the array is equal to 0, which indicates that it is empty. If it is, print “Array is empty” to the console. If it is not empty, print “Array is not empty” to the console.

c