Skip to content

Instantly share code, notes, and snippets.

@locnnil
Last active February 16, 2022 13:42
Show Gist options
  • Save locnnil/fb013945083312baa8639a1f24cdf617 to your computer and use it in GitHub Desktop.
Save locnnil/fb013945083312baa8639a1f24cdf617 to your computer and use it in GitHub Desktop.
Define the size of an array in C

The size of a Array in C

  • Using sizeof:
int a[17];
size_t n = sizeof(a) / sizeof(a[0]);
  • Using a Macro function
#define NELEMS(x)  (sizeof(x) / sizeof((x)[0]))

Code snippets getted from Stack Overflow from ansewer of Mark Harrison

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment