To determine the length of a statically allocated array, the sizeof operator can be used. - C Data Type

C examples for Data Type:sizeof

Description

To determine the length of a statically allocated array, the sizeof operator can be used.

Demo Code

#include <stdio.h>
int main(void) {
   int myArray[] = { 1, 2, 3 }; /* alternative */

   int length = sizeof(myArray) / sizeof(int); /* 2 */

   printf("%d", length);
}

Result


Related Tutorials