On this page
sizeof
Prev: builtins | Up: builtins | Next: _Alignof
Rel: size_t, Arrays & C Strings
Ref: cppreference — sizeof
Tags: #public #prog #c #builtins #tier/core
Availability
Built-in (Operator) — requires no #include header.
Syntax & Overview
sizeof(type) | sizeof expr
Compile-time operator (runtime only for VLAs) returning the size in bytes of a type or expression as size_t.
Notes & Pitfalls
- Never applies to decayed array parameters: Inside
void f(int arr[]),sizeof(arr)returns pointer size (8 bytes), not the array size—always passsize_t lenseparately.
Example
#include <assert.h>
#include <stddef.h>
int main(void) {
int arr[5] = {1, 2, 3, 4, 5};
size_t count = sizeof(arr) / sizeof(arr[0]);
assert(count == 5);
}
Linked from
Related notes
- tuts/c/builtins/_Alignof Linked here; links to this page; shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins Linked here; links to this page; shared tags: #builtins, #c, #prog
- tuts/c/stdlib/stddef/size_t Linked here; shared tags: #c, #prog, #tier
- tuts/c/fundamentals/arrays_and_strings Linked here; shared tags: #c, #prog
- tuts/c/builtins/__FILE__ shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/__func__ shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/__LINE__ shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/__STDC_VERSION__ shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/_Atomic shared tags: #builtins, #c, #prog, #tier
- tuts/c/builtins/_Generic shared tags: #builtins, #c, #prog, #tier