Color theme
0 day streak0 XPP1
CLearn mode
MISSION 1 OF 1

Measure a local array

0 XP earned
C track: AdvancedMission: AdvancedArray sizessizeofsize_t
Before you start this advanced track

Arrays and functions, plus the basics of memory addresses, pointers, and byte sizes.

Guided code reading and debugging. Runnable coding challenges are available in JavaScript, Python, and SQL.

x
0 / 2 challenges
LEARN THE CONCEPT

Understand it, then try it.

sizeof reports how many bytes an object occupies. For a local array, dividing the whole array’s size by one element’s size gives its element count. The result has type size_t, printed with %zu. This technique relies on having the array itself; a pointer does not retain the array’s size.

mission.c
#include <stdio.h>int main(void) {  int readings[] = {14, 18, 16, 21, 19};  size_t count = sizeof readings / sizeof readings[0];  printf("%zu readings\n", count);  return 0;}

Each example is a complete C11 console program. Compile as C, not C++. Arrays are local objects with the sizes shown; no input or external files are needed.

Track the values line by line. Predict the result before running this example in your own editor.