🌐
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.
🌐
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
parameters - What arguments does the sizeof operator take in C? - Stack Overflow
So technically, you're applying sizeof to (type), not to type. Really that's a distinction without a difference, but sizeof *p isn't "dropping the parentheses" any more that 1 + 2 is "dropping the parentheses" from (1) + (2). Unlike function calls, operators just don't need parentheses. More on stackoverflow.com
🌐 stackoverflow.com
what's the mechanism of sizeof() in C/C++? - Stack Overflow
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... More on stackoverflow.com
🌐 stackoverflow.com
c - sizeof style: sizeof(type) or sizeof variable? - Software Engineering Stack Exchange
I've seen two styles of using sizeof for memory-related operations (such as in memset or malloc): sizeof(type), and sizeof variable or sizeof(variable) Which one would you prefer, or would you use ... More on softwareengineering.stackexchange.com
🌐 softwareengineering.stackexchange.com
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 - Though for any given implementation of C or C++ the size of a particular datatype is constant, the sizes of even primitive types in C and C++ may be defined differently for different platforms of implementation. For example, runtime allocation of array space may use the following code, in which the sizeof operator is applied to the cast of the type int:
🌐
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.
🌐
Cppreference
en.cppreference.com › w › cpp › language › sizeof.html
sizeof operator - cppreference.com
December 29, 2024 - 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.
Find elsewhere
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.

🌐
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.
🌐
IBM
ibm.com › docs › en › xl-c-and-cpp-aix › 13.1.0
XL C/C++ for AIX
We cannot provide a description for this page right now
🌐
TutorialsPoint
tutorialspoint.com › cprogramming › c_sizeof_operator.htm
C - The sizeof Operator
C - Pointers vs. Multi-dimensional Arrays ... The sizeof operator is a compile−time unary operator. It is used to compute the size of its operand, which may be a data type or a variable.
🌐
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.
🌐
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 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 qualified 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.

🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › c language › difference-strlen-sizeof-string-c-reviewed
Difference between strlen() and sizeof() for string in C - GeeksforGeeks
July 23, 2025 - Data types supported: Sizeof gives actual size of any type of data (allocated) in bytes (including the null values) whereas get the length of an array of chars/string.
🌐
Microsoft Learn
learn.microsoft.com › en-us › cpp › cpp › sizeof-operator
sizeof Operator | Microsoft Learn
March 1, 2024 - When the sizeof operator is applied to an object of type char, it yields 1. When the sizeof operator is applied to an array, it yields the total number of bytes in that array, not the size of the pointer represented by the array identifier. To obtain the size of the pointer represented by the array identifier, pass it as a parameter to a function that uses sizeof.
🌐
GNU
gnu.org › software › c-intro-and-ref › manual › html_node › Type-Size.html
Type Size (GNU C Language Manual)
The expression sizeof arr gives the size of the array, not the size of a pointer to an element. However, if expression is a function parameter that was declared as an array, that variable really has a pointer type (see Array parameters are pointers), so the result is the size of that pointer.
🌐
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.
🌐
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 ...