🌐
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

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
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
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
June 11, 2013
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:
🌐
Cppreference
en.cppreference.com › w › cpp › language › sizeof.html
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.
🌐
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.
🌐
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.
Find elsewhere
🌐
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.
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.

🌐
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.
🌐
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.
🌐
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.
🌐
Programiz
programiz.com › c-programming › examples › sizeof-operator-example
C Program to Find the Size of int, float, double and char
February 10, 2026 - 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 printf("Size of int: %zu bytes\n", sizeof(intType)); printf("Size of float: %zu bytes\n", sizeof(floatType)); printf("Size of double: %zu bytes\n", sizeof(doubleType)); printf("Size of char: %zu byte\n", sizeof(charType)); return 0; }
🌐
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.
🌐
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.
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.

🌐
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. The sizeof() operator consists of just one operand that can either be a cast data type or an expression.
🌐
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
By using sizeof(*variable), the sizeof will always follow the correct type, presuming the programmer has the correct number of dereferences for what they're after. That being said, sizeof(*some_ptr) can look terrifying because it looks like you are dereferencing a null pointer prior to the allocation happening.
Top answer
1 of 16
1754

Executive summary:

int a[17];
size_t n = sizeof(a)/sizeof(a[0]);

Full answer:

To determine the size of your array in bytes, you can use the sizeof operator:

int a[17];
size_t n = sizeof(a);

On my computer, ints are 4 bytes long, so n is 68.

To determine the number of elements in the array, we can divide the total size of the array by the size of the array element. You could do this with the type, like this:

int a[17];
size_t n = sizeof(a) / sizeof(int);

and get the proper answer (68 / 4 = 17), but if the type of a changed you would have a nasty bug if you forgot to change the sizeof(int) as well.

So the preferred divisor is sizeof(a[0]) or the equivalent sizeof(*a), the size of the first element of the array.

int a[17];
size_t n = sizeof(a) / sizeof(a[0]);

Another advantage is that you can now easily parameterize the array name in a macro and get:

#define NELEMS(x)  (sizeof(x) / sizeof((x)[0]))

int a[17];
size_t n = NELEMS(a);
2 of 16
1120

The sizeof way is the right way iff you are dealing with arrays not received as parameters. An array sent as a parameter to a function is treated as a pointer, so sizeof will return the pointer's size, instead of the array's.

Thus, inside functions this method does not work. Instead, always pass an additional parameter size_t size indicating the number of elements in the array.

Test:

#include <stdio.h>
#include <stdlib.h>

void printSizeOf(int intArray[]);
void printLength(int intArray[]);

int main(int argc, char* argv[])
{
    int array[] = { 0, 1, 2, 3, 4, 5, 6 };

    printf("sizeof of array: %d\n", (int) sizeof(array));
    printSizeOf(array);

    printf("Length of array: %d\n", (int)( sizeof(array) / sizeof(array[0]) ));
    printLength(array);
}

void printSizeOf(int intArray[])
{
    printf("sizeof of parameter: %d\n", (int) sizeof(intArray));
}

void printLength(int intArray[])
{
    printf("Length of parameter: %d\n", (int)( sizeof(intArray) / sizeof(intArray[0]) ));
}

Output (in a 64-bit Linux OS):

sizeof of array: 28
sizeof of parameter: 8
Length of array: 7
Length of parameter: 2

Output (in a 32-bit windows OS):

sizeof of array: 28
sizeof of parameter: 4
Length of array: 7
Length of parameter: 1