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 ...
๐ŸŒ
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

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
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
parameters - What arguments does the sizeof operator take in C? - Stack Overflow
Since you can use parentheses with variables, I simply use 'sizeof(whatever)' always using parentheses; this infuriated a colleague who was adamant that it was crucial to distinguish between the variable and type usages - a distinction I still find to be without value. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Confuso da sizeof integer in C
e dice che per un intero, la dimensione minima in bit รจ 16. Quindi uso sizeof su una variabile int in questo modo: More on reddit.com
๐ŸŒ r/learnprogramming
15
0
October 14, 2024
๐ŸŒ
W3Schools
w3schools.com โ€บ c โ€บ c_data_types_sizeof.php
C sizeof operator
Which means if you have an array of 1000 char values, it will occupy 1000 bytes (1 KB) of memory. Using the right data type for the right purpose will save memory and improve the performance of your program. You will learn more about the sizeof operator later in this tutorial, and how to use it in different scenarios.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ sizeof() in c
sizeof() in C - Scaler Topics
January 12, 2024 - The sizeof() operator returns an unsigned integer value which represents the amount of memory in bytes occupied by the operand. We can use the %lu access specifier to print this data type(unsigned integer) using the printf statement.
๐ŸŒ
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.
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:

Copy#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.

Copyint 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:

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

Are equivalent.

๐ŸŒ
Cppreference
en.cppreference.com โ€บ w โ€บ c โ€บ language โ€บ sizeof.html
sizeof operator - cppreference.com
Number of elements in any array a including VLA(since C99) may be determined with the expression sizeof a / sizeof a[0]. Note that if a has pointer type (such as after array-to-pointer conversion of function parameter type adjustment), this expression would simply divide the number of bytes in a pointer type by the number of bytes in the pointed type.
Find elsewhere
๐ŸŒ
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); }
๐ŸŒ
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.
๐ŸŒ
SEI CERT
wiki.sei.cmu.edu โ€บ confluence โ€บ display โ€บ c โ€บ EXP09-C.+Use+sizeof+to+determine+the+size+of+a+type+or+variable
EXP09-C. Use sizeof to determine the size of a type or variable - SEI CERT C Coding Standard - Confluence
EXP09-C-EX1: The C Standard explicitly declares sizeof(char) == 1, so any sizes based on characters or character arrays may be evaluated without using sizeof. This does not apply to char* or any other data types. Porting code with hard-coded sizes can result in a buffer overflow or related ...
๐ŸŒ
Programiz
programiz.com โ€บ c-programming โ€บ examples โ€บ sizeof-operator-example
C Program to Find the Size of int, float, double and char
The sizeof(variable) operator computes the size of a variable. And, to print the result returned by sizeof, we use either %lu or %zu format specifier. #include<stdio.h> int main() { int intType; float floatType; double doubleType; char charType; // sizeof evaluates the size of a variable ...
๐ŸŒ
Linux Hint
linuxhint.com โ€บ sizeof_c_language
Sizeof() Operator in C Language โ€“ Linux Hint
Then, weโ€™ll apply what we learned ... in different cases. ... The sizeof() operator returns a size_t which contains the number of bytes that is occupied by a particular data type, variable, array, structure, or memory block....
๐ŸŒ
BYJUS
byjus.com โ€บ gate โ€บ sizeof-operator-in-c
The Requirement of sizeof() Operator in C Programs
August 1, 2022 - We generally use the sizeof() operator in the C language so that we can determine the sizes of the data types or the expressions that are specified in the storage units of char-size.
๐ŸŒ
Reddit
reddit.com โ€บ r/programming โ€บ how sizeof works in c/c++
r/programming on Reddit: How sizeof works in C/C++
June 13, 2017 - The second form is sizeof ( type-name ), which yields the size in bytes of (an object of) the given type. For example, sizeof 42 == sizeof (int), and sizeof (int[42]) == 42 * sizeof (int).
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ operators โ€บ sizeof
C | Operators | sizeof | Codecademy
June 13, 2025 - The sizeof operator returns the size in bytes as an unsigned integer value of type size_t. This example demonstrates how to use sizeof with basic C data types to determine their memory requirements:
๐ŸŒ
Unstop
unstop.com โ€บ home โ€บ blog โ€บ the sizeof() operator in c with detailed code examples
The Sizeof() Operator In C With Detailed Code Examples
March 19, 2024 - The sizeof() operator in C determines the size of an operand, which can be a data type, variable, expression, or pointer. But it must be used with caution.
๐ŸŒ
DEV Community
dev.to โ€บ 0xog_pg โ€บ under-the-hood-the-importance-of-sizeof-in-c-and-c-3hc4
Under the hood: The Importance of sizeof in C and C++ - DEV Community
July 15, 2023 - The output of this code in the current form will be ยท Original array: 1.000000 2.000000 3.000000 4.000000 5.000000 New array: 1.000000 2.000000 ยท This may seem strange initially but it's actually very straight forward. sizeof works if the size is known at compile time and to create dynamic arrays, you usually use a pointer (which will have a different size depending on the architecture of the CPU used), the size of a pointer is fixed, regardless of the data type.
๐ŸŒ
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 - size is the variable name that stores the size of the array, and datatype specifies the type of data value stored in size. sizeof(array_name) calculates the size of the array in bytes.