🌐
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
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 ...
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
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
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 - 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.
🌐
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.

🌐
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); }
Find elsewhere
🌐
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.
🌐
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 ...
🌐
cppreference.com
en.cppreference.com › c › language › sizeof
sizeof operator - cppreference.com
2) Returns the size, in bytes, of the object representation of the type of expression. No implicit conversions are applied to expression. Depending on the computer architecture, a byte may consist of 8 or more bits, the exact number provided as CHAR_BIT. sizeof(char), sizeof(signed char), and ...
🌐
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 ...
🌐
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.
🌐
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....
🌐
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:
🌐
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).
🌐
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.
🌐
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.
🌐
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.
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.