๐ŸŒ
W3Schools
w3schools.com โ€บ c โ€บ c_data_types_sizeof.php
C sizeof operator
The memory size refers to how much space a type occupies in the computer's memory. To actually get the size (in bytes) of a data type or variable, use the sizeof operator:
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ sizeof-operator-c
sizeof operator in C - GeeksforGeeks
sizeof() operator is a very useful tool that helps programmers understand how much memory a variable or data type occupies in the computer's memory.
Published ย  October 17, 2025
Discussions

How sizeof works in C/C++
The nittiest of all nitpicks: According to the C Specification ISO/IEC 9899:TC3 Chapter 5.2.4.2.1 (the first one I could find on google) it is 1 byte (8 bits). A (C) byte is at least 8 bits, not necessarily exactly 8 bits. Of course, if you can give me a platform that's actually in common use today that doesn't have 8-bit bytes, I'll eat... well, I'll eat my lunch, which I'm about to do anyway. But I'll do it while surprised. :-) So here is the takeaway, since the space needed for a fixed size array (like arr1) is calculated at compile time, the compiler knows about it and by proxysizeof knows about it. All that the compiler knows about arrays allocated at runtime (likearr2) is that it is a int*, which in this case is 8bytes. Incidentally, post also dances around the fact that this example definitively establishes that "arrays are just pointers" is not true, and is a somewhat common misconception about C and C++. Arrays decay to pointers if you look at them funny, but that doesn't make them the same, and sometimes the differences can rear their head. Compare const char * s = "foo"; vs const char s[] = "foo"; for example (in the context of a global/static variable). (That will show up differently in other cases too.) More on reddit.com
๐ŸŒ r/programming
30
53
June 13, 2017
what's the mechanism of sizeof() in C/C++? - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... Save this question. Show activity on this post. ... So, the compiler put directly the constant "4" as parameters of printf add call it. Then what does sizeof do? More on stackoverflow.com
๐ŸŒ stackoverflow.com
Understanding the sizeof operator in C - Stack Overflow
Why the sizeof operator gives different output for same character? Please Help ... Because 'A' doesn't have a type. It's being interpreted as an int. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Does sizeof return the number of bytes or the number of octets of a type in C? - Stack Overflow
Simply put in C and variants (unlike ... targets can vary greatly, and there is really no guarantee unless you use the fixed width types defined in stdint.h, and even then your implemenation has to support them. Anyway hypothetically(because on most modern machines a byte is an octet, for networking purposes I assume(ASCII)) does sizeof return the ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
cppreference.com
en.cppreference.com โ€บ cpp โ€บ language โ€บ sizeof
sizeof operator - cppreference.com
When applied to a class type, the result is the number of bytes occupied by a complete object of that class, including any additional padding required to place such object in an array. The number of bytes occupied by a potentially-overlapping subobject may be less than the size of that object. The result of sizeof is always nonzero, even if applied to an empty class type.
unary operator
sizeof is a unary operator in the C and C++ programming languages that evaluates to the storage size of an expression or a data type, measured in units sized as char. Consequently, โ€ฆ Wikipedia
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ Sizeof
sizeof - Wikipedia
January 11, 2026 - sizeof is a unary operator in the C and C++ programming languages that evaluates to the storage size of an expression or a data type, measured in units sized as char. Consequently, the expression sizeof(char) evaluates to 1. The number of bits of type char is specified by the preprocessor macro ...
๐ŸŒ
Reddit
reddit.com โ€บ r/programming โ€บ how sizeof works in c/c++
r/programming on Reddit: How sizeof works in C/C++
June 13, 2017 - So sizeof 42 is valid, and yields the size in bytes of type int. (You can write that as sizeof (42) if you prefer, but the parentheses are part of the operand expression, not part of the syntax of sizeof.) It's very common for the operand expression to be the name of an object, but it can be just about anything.
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ what-is-the-sizeof-function-in-c
What is the sizeof() function in C?
The sizeof()function in C is a built-in function that is used to calculate the size (in bytes)that a data type occupies in โ€‹the computerโ€™s memory.
Find elsewhere
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ operators โ€บ sizeof
C | Operators | sizeof | Codecademy
June 13, 2025 - The sizeof operator is a compile-time unary operator in C that returns the size in bytes of its operand. It calculates the memory space required to store a data type or variable, returning an unsigned integer value of type size_t.
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ cpp โ€บ c-language โ€บ sizeof-operator-c
sizeof Operator (C) | Microsoft Learn
August 3, 2021 - The result is an unsigned integral constant. The standard header STDDEF.H defines this type as size_t. When you apply the sizeof operator to an array identifier, the result is the size of the entire array rather than the size of the pointer represented by the array identifier.
Top answer
1 of 9
35

You know, there's a reason why there are standard documents (3.8MB PDF); C99, section 6.5.3.4, ยง2:

The sizeof operator yields the size (in bytes) of its operand, which may be an expression or the parenthesized name of a type. The size is determined from the type of the operand. The result is an integer. If the type of the operand is a variable length array type, the operand is evaluated; otherwise, the operand is not evaluated and the result is an integer constant.


In response to ibread's comment, here's an example for the C99 variable length array case:

#include <stdio.h>

size_t sizeof_int_vla(size_t count)
{
    int foo[count];
    return sizeof foo;
}

int main(void)
{
    printf("%u", (unsigned)sizeof_int_vla(3));
}

The size of foo is no longer known at compile-time and has to be determined at run-time. The generated assembly looks quite weird, so don't ask me about implementation details...

2 of 9
17

sizeof is an operator, not a function.

It's usually evaluated as compile time - the exception being when it's used on C99-style variable length arrays.

Your example is evaluating sizeof(int), which is of course known at compile time, so the code is replaced with a constant and therefore the ++ doesn't exist at run-time to be executed.

int i=0;
cout << sizeof(++i) << endl;
cout << i << endl;

It's also worth noting that since it's an operator, it can be used without the brackets on values:

int myVal;
cout << sizeof myVal << endl;
cout << sizeof(myVal) << endl;

Are equivalent.

๐ŸŒ
Quora
quora.com โ€บ Why-is-the-sizeof-operator-in-C-programming-not-a-function
Why is the sizeof operator in C programming not a function? - Quora
Answer (1 of 3): The sizeof operator is a unary operator because it has to work with both expressions and data types. The data type operand is actually a cast, which is why parentheses are required in this case. It has to evaluate at compile time, not at run time (with one exception, noted below)...
Top answer
1 of 4
32

Answer: sizeof returns the size of the type in bytes.


Example: sizeof(char) is 100% guaranteed to be 1, but this does not mean, that it's one octet (8 bits).


Proved by the standard:

in 6.5.3.4, point 2:

The sizeof operator yields the size (in bytes) of its operand, which may be an expression or the parenthesized name of a type. The size is determined from the type of the operand. The result is an integer. If the type of the operand is a variable length array type, the operand is evaluated; otherwise, the operand is not evaluated and the result is an integer constant.

...

When applied to an operand that has type char, unsigned char, or signed char, (or a quali๏ฌed version thereof) the result is 1. When applied to an operand that has array type, the result is the total number of bytes in the array) When applied to an operand that has structure or union type, the result is the total number of bytes in such an object, including internal and trailing padding.

Also, in Section 3.6, point 3:

A byte is composed of a contiguous sequence of bits, the number of which is implementation-defined

2 of 4
7

sizeof always returns size as the number of bytes. But according to wikipedia:

In the programming languages C and C++, the unary operator sizeof is used to calculate the size of any datatype, measured in the number of bytes required to represent the type. A byte in this context is the same as an unsigned char, and may be larger than 8 bits, although that is uncommon.

๐ŸŒ
Quora
quora.com โ€บ Why-is-sizeof-implemented-as-an-operator-in-C
Why is sizeof() implemented as an operator in C? - Quora
Answer (1 of 10): sizeof() is implemented as an operator evaluated by the compiler, at least in part, because knowing the size of a data type is implicit to making pointer arithmetic work in C. Consider the following code: [code]static int base; int *p = &base; int *q = p + 1;[/code] If you we...
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ how-to-find-the-size-of-an-array-in-c-with-the-sizeof-operator
How to Find the Size of an Array in C with the sizeof Operator
December 5, 2022 - C does not provide a built-in way to get the size of an array. With that said, it does have the built-in sizeof operator, which you can use to determine the size.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ cprogramming โ€บ c_sizeof_operator.htm
C - The sizeof Operator
We first find the size of the array and then divide it by the size of its data type. #include <stdio.h> int main(){ int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int y = sizeof(arr)/sizeof(int); printf("No of elements in arr: %d\n", y); }
๐ŸŒ
Arduino Forum
forum.arduino.cc โ€บ projects โ€บ programming
sizeof function, operation inside a function - Programming - Arduino Forum
September 3, 2013 - I understand what sizeof() is doing ... Serial.println(sizeof(other)); Serial.println(); foo(myStr, other); } void foo(char xxx[], char * yyy) { char ......
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ sizeof() in c
sizeof() in C - Scaler Topics
January 12, 2024 - Choose from our industry-leading programs designed for career success ... As we can see here, the sizeof() operator prints the size of the memory that the variable x occupies and not the value it holds, which means that the variable x will occupy the same amount of memory no matter the value it holds.
๐ŸŒ
Quora
quora.com โ€บ What-is-the-sizeof-operator-in-C-and-what-does-it-do
What is the sizeof() operator in C and what does it do? - Quora
Answer (1 of 3): First, as the question notes, sizeof is an operator (specifically a unary compile-time operator), not a function and it does not require parenthesis surrounding the object that is its single argument. The only correct reason to use parenthesis around the argument to sizeof is if ...