sizeof()

Anonymous contributor's avatar
Anonymous contributor
Published Feb 8, 2025
Contribute to Docs

In C, the sizeof() operator returns an integer representing the memory size of a data type or variable in bytes.

Syntax

sizeof(input)
  • input: The data type or variable whose memory size is to be calculated.

Example

The following example demonstrates the usage of the sizeof() operator:

#include <stdio.h>
int main() {
// Calculate the memory size of the 'int' data type
int res = sizeof(int);
// Print the result
printf("Size of int: %d bytes\n", res);
return 0;
}

The above code produces the following output:

Size of int: 4 bytes

All contributors

Contribute to Docs

Learn C on Codecademy